淘先锋技术网

首页 1 2 3 4 5 6 7
import tkinter
from tkinter import messagebox
import random

caishuzi = tkinter.Tk()                    
caishuzi.title('猜数字游戏')               
caishuzi.geometry('400x300')               
number = random.randint(1,100)

label1 = tkinter.Label(caishuzi,fg='black',text="猜数字小游戏",font=('正楷',10,'bold'))      
label1.place(x=10,y=10,height=60,width=160)                         

label2 = tkinter.Label(caishuzi,fg='black',text="游戏规则:\n从1到100中猜数字!!!",font=('正楷',10,'bold'))    
label2.place(x=10,y=60,height=60,width=160)

label3 = tkinter.Label(caishuzi,fg='black',text="请输入你所猜测的数字:",font=('正楷',10,'bold'))
label3.place(x=10,y=110,height=60,width=160)

text = tkinter.Entry(caishuzi,width=30)
text.place(x=10,y=160,height=60,width=160)

def compare():
    use = int(text.get())
    if use > number:
        tkinter.messagebox.showinfo('不正确', '大了')

    elif use < number:
        tkinter.messagebox.showinfo('不正确', '小了')

    elif use == number:
        tkinter.messagebox.showinfo('正确', '好牛蛙666')

    else :
        tkinter.messagebox.showerror('不正确')


button1 = tkinter.Button(caishuzi, text='确定',command=compare, width=10, font=('正楷', 10,))          
button1.place(x=70,y=160,height=60,width=160)

button2 = tkinter.Button(caishuzi, text='退出游戏',command=shuzi.quit, width=10, font=('正楷', 10,))
button2.place(x=70,y=210,height=60,width=160)

caishuzi.mainloop()