Python教程 - Tkinter Bingo小游戏

import tkinter
import tkinter.messagebox
import random

bingo = random.randint(1,100)

def btn_click():
    num = int(e.get())
    if num > bingo:
        l.config(text="It is bigger")
    elif num < bingo:
        l.config(text="It is smaller")
    else:
        tkinter.messagebox.showinfo("Tips","Bingo!")
        main.destroy()

main = tkinter.Tk()
main.title('Hello tkinter')
main.geometry('300x200')

l = tkinter.Label(main, text='Guess a number:')
l.config(bg='red')
l.config(fg='white')
l.config(height=2)
l.config(width=20)
l.pack()

e = tkinter.Entry(main)
e.insert(0,'50')
e.pack()

b = tkinter.Button(main,text='OK')
b.config(bg='green')
b.config(command=btn_click)
b.pack()

main.mainloop()

posted @ 2022-03-13 18:33  hgrun  阅读(154)  评论(0编辑  收藏  举报