tkinter Frame问题
import tkinter as tkimport tkinter.messagebox as msg
import pickle
class Login:
urse_data = {}
try:
with open('D:\\python库\\urse_data.pkl', 'rb') as data:
data = pickle.load(data)
urse_data = data
except:
with open('D:\\python库\\urse_data.pkl', 'wb') as data:
pickle.dump(urse_data,data)
def __init__(self,root):
self.main_window = root
self.main_window.title('welcoe to Login window')
self.main_window.geometry('450x300')
self.main_frame = tk.Frame(self.main_window)
self.main_frame.pack(padx=10,pady=10)
self.img = tk.PhotoImage(file='C:\\Users\\Admin\\Desktop\welcome.gif')
imglabel = tk.Label(self.main_frame, image=self.img)
imglabel.grid(row=1, column=2)
tk.Button(text='log on',command=self.log_on, width=6, height=2).place(x=100,y=230) # 登录组件
tk.Button(text='register', command=self.register,width=6, height=2).place(x=260, y=230) # 注册组件
tk.Label(self.main_window, text='ID',font=('微软雅黑', 13)).place(x=80, y=140)# ID 标签
tk.Label(text='Password', font=('微软雅黑', 13)).place(x=80, y=170) # 密码标签
self.id_ = tk.Entry(self.main_frame)# id 输入框
self.password = tk.Entry(self.main_frame)# 密码输入框
self.id_.place(x=170, y=140)
self.password.place(x=170, y=170)
def log_on(self):
try:
if self.password.get() == self.urse_data:
msg.showwarning(title='提示', message='登录成功')
else:
error_label = tk.Label(self.main_frame, text='账号或密码错误', font=('微软雅黑字体', 10))
error_label.place(x=170, y=190)
except KeyError:
error_label = tk.Label(self.main_frame, text='账号为空', font=('微软雅黑字体', 10))
error_label.place(x=170, y=190)
def register(self):
pass
root = tk.Tk()
longin = Login(root)
root.mainloop()
为什么当我的组件的父组件指定为self.main_frame的时候组件无法显示,也不报错 发一下那个 pkl
页:
[1]