哦嚯,我不会 2021-07-20 19:50 采纳率: 83.3%
浏览 83
已采纳

python 报错没整明白,求解!

代码运行前没报错,也能正常打开窗口,但一点击“log in”以后,pycharm就报错了(报错代码和图片在文章结尾)
thank you very much!

下面是代码:

import tkinter as tk
from tkinter import messagebox
import pickle

window = tk.Tk()
window.title('our speak')
window.geometry('800x550')

canvas = tk.Canvas(window, height=180, width=720)
image_file = tk.PhotoImage(file=r'C:\Users\HUAWEI\Desktop\logo.gif')
image = canvas.create_image(0, 0, anchor='nw', image=image_file)
canvas.pack(side='top')

tk.Label(window, text='User name:', font=('Arial', 18)).place(x=148, y=233)
tk.Label(window, text='Pass word:', font=('Arial', 18)).place(x=153, y=293)

var_usr_name = tk.StringVar()
var_usr_pwd = tk.StringVar()

entry_usr_name = tk.Entry(window, textvariable=var_usr_name)
entry_usr_name.place(width=300, height=30)
entry_usr_name.place(x=310, y=235)

entry_usr_pwd = tk.Entry(window, textvariable=var_usr_pwd, show='●')
entry_usr_pwd.place(width=300, height=30)
entry_usr_pwd.place(x=310, y=295)


def usr_login():
    usr_name = var_usr_name.get()
    usr_pwd = var_usr_pwd.get()
    try:
        with open('usrs_info.pickle', 'rb') as usr_file:
            usrs_info = pickle.load(usr_file)
    except FileNotFoundError:
        with open('usrs_info.pickle', 'wb') as usr_file:
            usrs_info = {'admin': 'cfy20080920'}
            pickle.dump(usrs_info, usr_file)
    if usr_name in usrs_info:
        if usr_pwd == usrs_info[usr_name]:
            tk.messagebox.showinfo(title='Welcome', message='How are you? ' + usr_name)
        else:
            tk.messagebox.showerror(message='Error, your password is wrong, try again.')
    else:
        is_sign_up = tk.messagebox.askyesno('Welcome',
                                            'You have not signed up yet. Sign up today?')
        if is_sign_up:
            usr_sign_up()


def usr_sign_up():
    def sign_to_mofan_python():
        np = new_pwd.get()
        npf = new_pwd_confirm.get()
        nn = new_name.get()
        with open('usrs_info.pickle', 'rb') as usr_file:
            exist_usr_info = pickle.load(usr_file)
        if np != npf:
            tk.messagebox.showerror('Error', 'Password and confirm password must be the same!')
        elif nn in exist_usr_info:
            tk.messagebox.showerror('Error', 'The user has already signed up!')
        else:
            exist_usr_info[nn] = np
            with open('usrs_info.pickle', 'wb') as usr_file:
                pickle.dump(exist_usr_info, usr_file)
            tk.messagebox.showinfo('Welcome!', 'You have successfully signed up!')
            window_sign_up.destroy()

    window_sign_up = tk.Toplevel(window)
    window_sign_up.geometry('350x200')
    window_sign_up.title('Sign up window')

    new_name = tk.StringVar()
    tk.Label(window_sign_up, text='User name: ').place(x=50, y=10)
    entry_new_name = tk.Entry(window_sign_up, textvariable=new_name)
    entry_new_name.place(x=150, y=10)

    new_pwd = tk.StringVar()
    tk.Label(window_sign_up, text='Password: ').place(x=50, y=50)
    entry_usr_psswd = tk.Entry(window_sign_up, textvariable=new_pwd, show='●')
    entry_usr_psswd.place(x=150, y=50)

    new_pwd_confirm = tk.StringVar()
    tk.Label(window_sign_up, text='Confirm password: ').place(x=10, y=90)
    entry_usr_pwd_confirm = tk.Entry(window_sign_up, textvariable=new_pwd_confirm, show='●')
    entry_usr_pwd_confirm.place(x=150, y=90)

    btn_comfirm_sign_up = tk.Button(window_sign_up, text='Sign up', command=sign_to_mofan_python)
    btn_comfirm_sign_up.place(x=150, y=130)


btn_login = tk.Button(window, text='Login', font=('Arial', 12), command=usr_login, bg="light blue", height=2, width=30)
btn_login.place(x=320, y=345)
btn_sign_up = tk.Button(window, text='Sign up', font=('Arial', 10), command=usr_sign_up, bg="light blue", height=1,
                        width=8)
btn_sign_up.place(x=423, y=415)

window.mainloop()

报错代码:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\HUAWEI\AppData\Local\Programs\Python\Python39\lib\tkinter_init_.py", line 1892, in call
return self.func(*args)
File "D:\python\项目\our speak2.py", line 34, in usr_login
usrs_info = pickle.load(usr_file)
EOFError: Ran out of input

下面是图片原文件:
img

  • 写回答

1条回答 默认 最新

  • robot8me 2021-07-20 20:27
    关注

    没有报错。不过按照这个错误提示,应该是usr_file出问题了,可能是上次dump出了问题

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已采纳回答 7月21日
  • 创建了问题 7月20日

悬赏问题

  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。
  • ¥15 GitHubssh虚拟机连接不上
  • ¥15 装完kali之后下载Google输入法 重启电脑后出现以下状况 且退不出去 桌面消失 反复重启没用
  • ¥15 ESP-IDP-BLE配网连接wifi
  • ¥15 ue2.6.12版本用的若以,安装gojs,引入import * as go from 'gojs';报错
  • ¥15 服务器上的网站安装php5.6版本
  • ¥15 请大咖一起探索iptv 直播源的hls通过反向代理解密
  • ¥100 寻找技术员 云闪付tn转h5输入卡号付款的链接 重酬!