|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from tkinter import *
from tkinter import messagebox
class Login(object):
def __init__(self):
self.root = Tk()
self.root.title("**医药系统")
self.root.geometry('450x300')
self.bg_image = PhotoImage(file='cloud.png')
self.bg_label = Label(self.root,image=self.bg_image)
self.bg_label.place(x=0,y=0,relwidth=1,relheight=1)
self.canvas = Canvas(self.bg_label,height=150,width=300)
self.image_file = PhotoImage(file='cd.gif')
self.image = self.canvas.create_image(0,0,anchor='w',image=self.image_file)
self.canvas.pack(side='top')
self.label_account = Label(self.bg_label,text='account: ',)
self.label_account.place(x=80,y=170)
self.label_password = Label(self.bg_label,text='password:')
self.label_password.place(x=80,y=205)
self.input_account = Entry(self.bg_label,width='30')
self.input_account.place(x=150,y=170)
self.input_passeord = Entry(self.bg_label,width='30',show='*')
self.input_passeord.place(x=150,y=205)
self.login_button = Button(self.bg_label,text="login",command=self.backstage_interface)
self.login_button.place(x=140,y=235)
self.sigin_button = Button(self.bg_label,text="sigin",command=self.sigin_interface)
self.sigin_button.place(x=260,y=235)
number = [100,200,300,400]
def backstage_interface(self):
#self.root.destroy()
top = Toplevel(master=None)
top.geometry('200x100')
top.title("login demo")
act = self.input_account.get()
for each in list1():
if each == act:
msg = Message(top,text="成功")
msg.pack()
else:
msg = Message(top,text="不存在该用户")
msg.pack()
def sigin_interface(self):
self.root.destroy()
top = Toplevel()
top.geometry('300x200')
top.title("sigin demo")
account_lable = Label(top,text="账号:")
account_lable.grid(row=0,column=0,padx=5,pady=5)
password_lable = Label(top,text="密码:")
password_lable.grid(row=1,column=0,padx=5,pady=5)
repassword_lable = Label(top,text="再次确认密码:")
repassword_lable.grid(row=2,column=0,padx=5,pady=5)
account_entry = Entry(top,width='25')
account_entry.grid(row=0,column=1,padx=5,pady=5)
password_entry = Entry(top,width='25')
password_entry.grid(row=1,column=1,padx=5,pady=5)
repassword_entry = Entry(top,width='25')
repassword_entry.grid(row=2,column=1,padx=5,pady=5)
success_button = Button(top,text="注册",width=10,command=on_click) #问题在这一行,错误类型为:NameError: name 'on_click' is not defined
success_button.grid(row=3,column=0,sticky=W,padx=10,pady=5)
quit_button = Button(top,text="退出",width=10,command=top.quit)
quit_button.grid(row=3,column=1,sticky=E,padx=10,pady=5)
def on_click(self): #但这里定义了呀
messagebox.showinfo(parent=top,title='aaa',message="成功")
def main():
L = Login()
mainloop()
if __name__ == "__main__":
main()
你定义的是实例函数,而且层级比你定义button高
|
|