python建立一个窗口,python怎么做窗口程序
依据:莫凡大蟒
代码来源:哔哩哔哩视频
框架:张量流
库:tkinter(比较老,现在也有新的相关库)
(莫凡蟒蛇对于初学python,或者初入深度学习的伙伴们还是比较友好的。)
下图为实验结果图,可以点击下方两按钮,继续弹指令或操作。具体可在程序中更改窗口大小,相关指令,文字说明提示语等。
具体代码:
将图形界面作为tkfrom tkinter导入messagebox #导入此以修复messagebox错误进口提货窗口=tk .Tk()window.title(欢迎使用小python’)窗口。几何( 450 x300 )#用户信息Tk .标签(window,text=用户名:)。place(x=50,y=150)tk .标签(窗口,文本=迷人的小甜瓜: ).place(x=50,y=190)var _ usr _ name=tk。djc()var _ usr _ name。set( example @ python。com )entry _ usr _ name=tk .Entry(window,text变量=var _ usr _ name)entry _ usr _ name。place(x=160,y=150)var _ usr _ pwd=tk。djc()entry _ usr _ pwd=tk .Entry(window,textvariable=var_usr_pwd,show= * )entry _ usr _ pwd。place(x=160,y=190)def usr _ log in():usr _ name=var _ usr _ name。get()usr _ pwd=var _ usr _ pwd。get()try:with open( usrs _ info。pickle , Rb )作为usr _ file:usr _ info=pickle。load(usr _ file)except file not found错误:with open( usrusr _ name)else:tk。messagebox。显示错误(消息=错误,您的密码错误,请重试.)else:is _ sign _ up=tk。messagebox。问yes no(’欢迎,您还没有注册。"今天就报名吗?")if is _ sign _ up:usr _ sign _ up()def usr _ sign _ up():def sign _ to _莫凡_ Python():NP=new _ pwd。NPF=new _ pwd _ confirm。get()nn=new _ name。get()with open( usrs _ info。pickle , Rb )作为usr _ file:exist _ usr _ info=pickle。NP的话加载(usr _ file)!=NPF:tk。messagebox。显示错误(错误,迷人的小甜瓜和确认密码必须相同!)elif nn in exist _ usr _ info:tk。messagebox。显示错误(错误,用户已经注册了!)else:exist _ usr _ info[nn]=NP with open( usrs _ info。pickle , WB )作为usr _ file:pickle。dump(exist _ usr _ info,usr _ file)tk。messagebox。showinfo(欢迎,您已经成功注册了!)window _ sign _ up。destroy()window _ sign _ up=tk .顶层(窗口)window _ Sign _ up。几何( 350 x200 )窗口_注册。标题(注册窗口)new _ name=tk。djc()新名称。set( example @ python。com’)tk .Label(window_sign_up,text=用户名:)。place(x=10,y=10) entry_new_name=tk .Entry(window_sign_up,text变量=new _ name)entry _ new _ name。place(x=150,y=10) new_pwd=tk.djc() tk .Label(window_sign_up,text=迷人的小甜瓜: ).place(x=10,y=50) entry_usr_pwd=tk .Entry(window_sign_up,textvariable=new_pwd,show= * )entry _ usr _ pwd。place(x=150,y=50)new _ pwd _ confirm=tk。djc()tk .标签(window_sign_up,text=确认密码:)。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 _ confirm _ sign _ up=tk .Button(window_sign_up,text=注册,command=sign _ to _莫凡_ Python)BTN _ com公司_注册。place(x=150,y=130)#登录并注册按钮btn_login=tk .按钮(窗口,文本=登录,命令=usr _登录)BTN _登录。place(x=170,y=230)btn_sign_up=tk .按钮(window,text=注册,command=usr _ Sign _ up)BTN _注册。place(x=270,y=230)window.mainloop()希望对大家有所帮助,一起加油!
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。