图片 3

未分类

树立窗口windowwindow=tk.Tk(卡塔尔(英语:State of Qatar)

23 12月 , 2019  

图片 1

咱们后天的标题是,如何在登入分界面点了规定之后可以步向下八个分界面,从图1到图2图1图2上边是代码importtkinterastk#接收Tkinter前须求起初入importtkinter.messageboximportpickle#第1步,实例化object,组建窗口windowwindow=tk.Tk(卡塔尔#第2步,给窗口的可视化起名字window.title(‘WelcometoHongweiWebsite’卡塔尔(قطر‎#第3步,设定窗口的高低(长*宽)window.geometry(‘400×300′)#这里的乘是小x#第4步,加载wellcomeimagecanvas=tk.Canvas(window,width=400,height=135,bg=’green’)canvas.pack(side=’top’)tk.Label(window,text=’Welcome’,font=(‘Arial’,16)).pack()#第5步,客户音信tk.Label(window,text=’Username:’,font=(‘Arial’,14卡塔尔卡塔尔国.place(x=10,y=170卡塔尔tk.Label(window,text=’Password:’,font=(‘Arial’,14卡塔尔(英语:State of Qatar)卡塔尔(قطر‎.place(x=10,y=210卡塔尔(英语:State of Qatar)#第6步,客商登入输入框entry#用户名var_usr_name=tk.StringVar()var_usr_name.set(‘example@python.com’)entry_usr_name=tk.Entry(window,textvariable=var_usr_name,font=(‘Arial’,14))entry_usr_name.place(x=120,y=175)#客商密码var_usr_pwd=tk.StringVar()entry_usr_pwd=tk.Entry(window,textvariable=var_usr_pwd,font=(‘Arial’,14),show=’*’)entry_usr_pwd.place(x=120,y=215)#第8步,定义顾客登陆功效defusr_login():#这两行代码正是收获顾客输入的usr_name和usr_pwdusr_name=var_usr_name.get()usr_pwd=var_usr_pwd.get()#这里安装非常捕获,当大家先是次访问客户音讯文件时是官样文章的,所以这里安装非常捕获。#中间的两行就是我们的相称,即程序将输入的音讯和文件中的新闻相称。try:withopen(‘usrs_info.pickle’,’rb’)asusr_file:usrs_info=pickle.load(usr_file)exceptFileNotFoundError:#那边就是大家在未曾读取到`usr_file`的时候,程序会创建一个`usr_file`以此文件,并将组织者#的客户和密码写入,即客户名叫`admin`密码为`admin`。withopen(‘usrs_info.pickle’,’wb’)asusr_file:usrs_info={‘admin’:’admin’}pickle.dump(usrs_info,usr_file)usr_file.close()#必须先关闭,不然pickle.load(卡塔尔国相会世EOFError:Ranoutofinput#假如顾客名和密码与公事中的相配成功,则会报到成功,并跳出弹窗howareyou?加上你的顾客名。ifusr_nameinusrs_info:ifusr_pwd==usrs_info[usr_name]:tkinter.messagebox.showinfo(title=’Welcome’,message=’Howareyou?’+usr_name)#假使客商名相称成功,而密码输入错误,则会弹出’Error,yourpasswordiswrong,tryagain.’else:tkinter.messagebox.showerror(message=’Error,yourpasswordiswrong,tryagain.’卡塔尔(قطر‎else:#举例开掘顾客名不设有is_sign_up=tkinter.messagebox.askyesno(‘Welcome!’,’Youhavenotsignupyet.Signupnow?’)#提示需不必要注册新客商ifis_sign_up:usr_sign_up()#第9步,定义顾客注册成效defusr_sign_up():defsign_to_Hongwei_Website():#以下三行就是收获大家报了名时所输入的音信np=new_pwd.get()npf=new_pwd_confirm.get()nn=new_name.get()#此间是张开大家记录数据的公文,将注册音讯读出withopen(‘usrs_info.pickle’,’rb’)asusr_file:exist_usr_info=pickle.load(usr_file)#此地便是剖断,借使五回密码输入不均等,则提示Error,Passwordandconfirmpasswordmustbethesame!ifnp!=npf:tkinter.messagebox.showerror(‘Error’,’Passwordandconfirmpasswordmustbethesame!’)#生龙活虎经顾客名早已在大家的数据文件中,则提醒Error,Theuserhasalreadysignedup!elifnninexist_usr_info:tkinter.messagebox.showerror(‘Error’,’Theuserhasalreadysignedup!’)#最终只要输入无上述错误,则将登记输入的音讯记录到文件当中,并指示注册成功Welcome!,Youhavesuccessfullysignedup!,然后销毁窗口。else:exist_usr_info[nn]=npwithopen(‘usrs_info.pickle’,’wb’)asusr_file:pickle.dump(exist_usr_info,usr_file)tkinter.messagebox.showinfo(‘Welcome’,’Youhavesuccessfullysignedup!’)#接下来销毁窗口。window_sign_up.destroy()#定义长在窗口上的窗口window_sign_up=tk.Toplevel(window)window_sign_up.geometry(‘300×200’)window_sign_up.title(‘Signupwindow’)new_name=tk.StringVar()#将输入的注册名赋值给变量new_name.set(‘example@python.com’)#将前期展现定为’example@python.com’tk.Label(window_sign_up,text=’Username:’).place(x=10,y=10)#将`Username:`停放在坐标。entry_new_name=tk.Entry(window_sign_up,textvariable=new_name)#创建二个注册名的`entry`,变量为`new_name`entry_new_name.place(x=130,y=10)#`entry`停放在坐标.new_pwd=tk.StringVar()tk.Label(window_sign_up,text=’Password:’).place(x=10,y=50)entry_usr_pwd=tk.Entry(window_sign_up,textvariable=new_pwd,show=’*’)entry_usr_pwd.place(x=130,y=50)new_pwd_confirm=tk.StringVar()tk.Label(window_sign_up,text=’Confirmpassword:’).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=130,y=90)#下面的sign_to_Hongwei_Websitebtn_comfirm_sign_up=tk.Button(window_sign_up,text=’Signup’,command=sign_to_Hongwei_Website)btn_comfirm_sign_up.place(x=180,y=120)#第7步,loginandsignup按钮btn_login=tk.Button(window,text=’Login’,command=usr_login)btn_login.place(x=120,y=240)btn_sign_up=tk.Button(window,text=’Signup’,command=usr_sign_up)btn_sign_up.place(x=200,y=240)#第10步,主窗口循环突显window.mainloop(卡塔尔国fromtkinterimport*fromtkinter.messageboximportshowinforoot=Tk(卡塔尔(قطر‎defcreate3(卡塔尔(قطر‎:top2=Toplevel(卡塔尔国top2.title(‘Python’卡塔尔(قطر‎Button(top2,text=’植物少年老成’,command=reply卡塔尔(英语:State of Qatar).grid(row=1,column=1,padx=1,pady=1卡塔尔(قطر‎Button(top2,text=’植物二’,command=reply卡塔尔.grid(row=1,column=2,padx=1,pady=1卡塔尔Button(top2,text=’植物三’,command=reply卡塔尔国.grid(row=1,column=3,padx=1,pady=1卡塔尔(英语:State of Qatar)defreply(卡塔尔国:showinfo(title=’新窗口’,message=’恭喜兑换到功’卡塔尔(英语:State of Qatar)defcreate(卡塔尔:top2=Toplevel(卡塔尔(قطر‎top2.title(‘Python’卡塔尔(قطر‎Button(top2,text=’瓶数’卡塔尔(قطر‎.grid(row=1,column=1,padx=1,pady=1卡塔尔defcreate2(卡塔尔(قطر‎:top1=Toplevel(卡塔尔(قطر‎top1.title(‘Python’卡塔尔国Button(top1,text=’兑换’,command=create卡塔尔.grid(row=1,column=1,padx=1,pady=1卡塔尔国Button(root,text=’兑换’,command=create3卡塔尔(英语:State of Qatar).pack(卡塔尔(英语:State of Qatar)Button(root,text=’投瓶’,command=create卡塔尔.pack(卡塔尔(英语:State of Qatar)mainloop(卡塔尔(英语:State of Qatar)感谢!

在沙窝窝派上采取 Python,对串口实行读写操作,遇到二个主题素材,上面是自己的生机勃勃有的代码
import tkinter as tk
from tkinter import messagebox # import this to fix messagebox error
import pickle
import serial
ser = serial.Serial(‘/dev/ttyS0’, 9600, parity=serial.PARITY_NONE)

小弟刚牵头攻读python,因为平日欣观赏游戏,所以做了四个网络游戏的赞助,为了绑定后台,调用了大漠插件,测量试验没不通常,但用pyinstaller打包后就不恐怕运行了谢谢那是代码#!/usr/bin/python#-*-coding:UTF-8-*-importtkinterastkimportwin32com.client,time,threading#调用大漠hwnd=0dm=win32com.client.Dispatch(‘dm.dmsoft’卡塔尔(قطر‎#绑定窗口defbind_dm():hwnd=int(var_hwnd.get())print(hwnd)dm.BindWindow(hwnd,”gdi2″,”windows”,”windows”,0)#脚本defrun():whileTrue:dm.MoveTo(300,400)dm.LeftDoubleClick()time.sleep(30)dm.MoveTo(600,100)dm.LeftDoubleClick()time.sleep(30)defthread_run(func,*args):t=threading.Thread(target=func,args=args)t.setDaemon(True)t.start()#成立窗口window=tk.Tk(卡塔尔window.title(“挂划船”卡塔尔(英语:State of Qatar)window.geometry(“200×200″卡塔尔#创办进程号变量var_hwnd=tk.Variable()caution_lb=tk.Label(window,text=”设置飞快键为F1,设置划船到3″卡塔尔.place(x=10,y=10卡塔尔hwnd_lb=tk.Label(window,text=”输入游戏经过号”卡塔尔(قطر‎.place(x=10,y=30卡塔尔(قطر‎hwnd_entry=tk.Entry(window,textvariable=var_hwnd,width=10).place(x=100,y=30)load_lb=tk.Button(window,text=”加载”,command=bind_dm).place(x=10,y=70)run_button=tk.Button(window,text=”开始”,command=lambda:thread_run(run)).place(x=70,y=70)window.mainloop()

图片 2

login and sign up button

btn_login = tk.Button(window, text=’Login’, command=usr_login)
btn_login.place(x=170, y=230)
btn_sign_up = tk.Button(window, text=’Sign up’,
command=usr_sign_up)
btn_sign_up.place(x=270, y=230)

def usr_config:
树立窗口windowwindow=tk.Tk(卡塔尔(英语:State of Qatar)。window_config = tk.Toplevel
window_config.title
window_config.geometry(‘200×200’)
print
var3 = usr_name

def print_selection():
value = lb.get(lb.curselection #从列表中光标选中的位置获取值赋给
value
var1 = ‘%d’ %value
var3 = usr_name
var4 = var3 +’I will back in’ + var1 + ‘minutes’
var5 = var4.encode()
print(ser.isOpen
ser.write
tk.messagebox.showinfo(title=’Confirmation’, message=’Your message has
been sent successfully’+ ‘/n’ + ‘message is:’ +var4)
window_config.destroy()

b1 = tk.Button(window_config, text=’print_selection’, width=15,
height=2, command=print_selection)
b1.pack()

var2 = tk.StringVar()
var2.set((11,22,33,44))
lb = tk.Listbox(window_config, listvariable=var2) #设置 listbox
list_items = [1,2,3,4]
lb.pack()

var3 = tk.StringVar()
var3.set

window.mainloop()

运作时不报错,然而下位机上的串口无法接受到 ser.write
通过串口发送的新闻
而自身一向在 IDLE 中逐风度翩翩输入’var =’I will back in 5 minutes”
var1 = var.encode()
“import serial”
“ser= serial.Serial(‘/dev/ttyAMA0’,9600)”
‘ser.open()’
‘ser.write’
下位机上的抽出程序是一心能够健康接纳的

大惑不解,跪求大神帮看看
图片 3


相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图