首页 > 编程 > Python > 正文

Python基础语法(4)——GUI编程及猜数字游戏

2019-11-06 07:39:41
字体:
来源:转载
供稿:网友
13 图形界面(GUI)及猜数字游戏1 GUI:Graphical User Interface2 tkinter:GUI library for Python3 GUI Example13.1 图形界面fromtkinterimport*importtkinter.messageboxasmbimporttkinter.simpledialogasdlroot=Tk()w=Label(root,text="Label")w.pack()mb.showinfo("welcome","welcome learnPython!")guess=dl.askinteger("Number","please input an number:")mb.showinfo("output:",guess)13.2 猜数字游戏fromtkinterimport*importtkinter.messageboxasmbimporttkinter.simpledialogasdlroot=Tk()number=66guessFlag=FalsewhileguessFlag==False:    guess=dl.askinteger("Number Game","please input the number:")   ifguess==number:        mb.showinfo("Congratulation","You win!")        guessFlag=True   elifguess>number:        mb.showinfo("Sorry","The number you input is bigger than true number!")   else:        mb.showinfo("Sorry","The number you input is smaller than true number!")
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表