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

13 图形界面(GUI)及猜数字游戏
1 GUI:Graphical User Interface
2 tkinter:GUI library for Python
3 GUI Example
13.1 图形界面
from tkinter import *
import tkinter.messagebox as mb
import tkinter.simpledialog as dl
root=Tk()
w=Label(root,text= "Label" )
w.pack()
mb.showinfo( "welcome" , "welcome learn Python!" )
guess=dl.askinteger( "Number" , "please input an number:" )
mb.showinfo( "output:" ,guess)

13.2 猜数字游戏
from tkinter import *
import tkinter.messagebox as mb
import tkinter.simpledialog as dl
root=Tk()
number= 66
guessFlag= False
while guessFlag== False :
    guess=dl.askinteger( "Number Game" , "please input the number:" )
    if guess==number:
        mb.showinfo( "Congratulation" , "You win!" )
        guessFlag= True
    elif guess>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!" )

你可能感兴趣的:(Python,学习笔记)