import random
import tkinter
from tkinter.messagebox import showerror,showinfo
from tkinter.simpledialog import askinteger

root = tkinter.Tk()

#root.overrideredirect(1)                 # 去除窗口边框
root.attributes('-alpha',0.9)              #半透明
root.attributes("-topmost", True)     # 永远处于顶层

#导入时间库
import datetime

X = tkinter.IntVar(value = 0)
Y = tkinter.IntVar(value = 0)
canMove = tkinter.IntVar(value = 0)
still = tkinter.IntVar(value = 1)

labelDataTime = tkinter.Label(root,width = 130)
labelDataTime.pack(fill = tkinter.BOTH,expand = tkinter.YES)
labelDataTime.configure(bg = 'yellow')

def onLeftButtonDown(event):
    root.attributes('-alpha',0.4)
    X.set(event.x)
    Y.set(event.y)
    canMove.set(1)

labelDataTime.bind('<Button-1>',onLeftButtonDown)

def onLeftButtonUp(event):
    root.attributes('-alpha',0.9)
    canMove.set(0)
    
labelDataTime.bind('<ButtonRelease-1>',onLeftButtonDown)

def quit_button(event):
    but1 = tkinter.Button(root, text = '退出', width = 10,height = 2,command = root.quit)
    but1.pack()

#窗口标题
root.title('猜数游戏')

#窗口初始大小和位置
root.geometry('720x720+500+200')


#不允许改变窗口大小
root.resizable(False, False)

#用户猜的数
varNumber = tkinter.StringVar(root, value='0')

#允许猜的总次数
totalTimes = tkinter.IntVar(root, value=0)

#已猜次数
already = tkinter.IntVar(root, value=0)

#当前生成的随机数
currentNumber = tkinter.IntVar(root, value=0)

#玩家玩游戏的总次数
times = tkinter.IntVar(root, value=0)

#玩家猜对的总次数
right = tkinter.IntVar(root, value=0)
lb = tkinter.Label(root, text='请输入一个整数：')
lb.place(x=10, y=10, width=100, height=20)

#用户猜数并输入的文本框
entryNumber = tkinter.Entry(root, width=140, textvariable=varNumber)
entryNumber.place(x=110, y=10, width=140, height=20)
#只有开始游戏以后才允许输入
entryNumber['state'] = 'disabled'

#按钮单击事件处理函数
def buttonClick():
    if button['text']=='Start Game':
    #每次游戏时允许用户自定义数值范围
    #玩家必须输入正确的数
    #最小数值
        while True:
            try:
                start = tkinter.simpledialog.askinteger('允许的最小整数',
                                                                            '最小数',
                                                                            initialvalue=1)
                if start != None:
                    assert start > 0
                    break
            except:
                pass
        #最大数值
        while True:
            try:
                end = askinteger('允许的最大整数',
                                           '最大数',
                                            initialvalue = 11)
                if end != None:
                    assert end > 10 and end > start
                    break
            except:
                pass
            
        #在用户自定义的数值范围内生成随机数
        currentNumber.set(random.randint(start, end))

         #用户自定义一共允许猜几次
         #玩家必须输入正确的整数
        while True:
            try:
                t = askinteger('最多允许猜几次？',
                                           '总次数',
                                           initialvalue=3)
                if t  != None:
                    assert t > 0
                    totalTimes.set(t)
                    break
            except:
                pass
        #已猜次数初始化为0
        already.set(0)
        button['text'] = '剩余次数：' + str(t)

        #把文本框初始化为0
        varNumber.set('0')

        #允许用户开始输入整数
        entryNumber['state'] = 'normal'

        #玩游戏的次数加1
        times.set(times.get()  +  1)
    else:
        #一共允许猜几次
        total = totalTimes.get()

         #本次游戏的正确答案
        current = currentNumber.get()

         #玩家本次猜的数
        try:
            x = int(varNumber.get())
        except:
            showerror('抱歉', '必须输入整数')
            return
        #猜对了
        if x == current:
            showinfo('恭喜', '猜对啦')
            button['text'] = 'Start Game'

             #禁用文本框
            entryNumber['state'] = 'disabled'

            #猜对的次数加1
            right.set(right.get() + 1)
        else:
            #已猜次数加1
            already.set(already.get()+1)

            if x > current:
                showerror('抱歉', '猜的数太大了')
            else:
                showerror('抱歉', '猜的数太小了')

            #可猜次数用完了
            if already.get() == total:
                showerror('抱歉', '游戏结束了，正确的数是：'+
                                                  str(currentNumber.get()))

                button['text'] = 'Start Game'
                #禁用文本框
                entryNumber['state'] = 'disabled'
            else:
                button['text'] = '剩余次数：' + str(total-already.get())

#在窗口上创建按钮，并设置事件处理函数   
button = tkinter.Button(root, text='Start Game', command=buttonClick)
button.place(x=10, y=40, width=250, height=20)
            
#关闭程序时提示战绩
def closeWindow():
    message = '本次共玩游戏 {0} 次，猜对 {1} 次！\n欢迎下次再玩！'
    message = message.format(times.get(),right.get())
    showinfo('战绩', message)
    root.destroy()
root.protocol('WM_DELETE_WINDOW', closeWindow)
      
#启动消息主循环
root.mainloop()
            
            
            
            
            
            
            
            
fdd1ac04171971fd9cd1a60d3ad0b09920034661
<mask token>


def onLeftButtonUp(event):
    root.attributes('-alpha', 0.9)
    canMove.set(0)


<mask token>


def buttonClick():
    if button['text'] == 'Start Game':
        while True:
            try:
                start = tkinter.simpledialog.askinteger('允许的最小整数', '最小数',
                    initialvalue=1)
                if start != None:
                    assert start > 0
                    break
            except:
                pass
        while True:
            try:
                end = askinteger('允许的最大整数', '最大数', initialvalue=11)
                if end != None:
                    assert end > 10 and end > start
                    break
            except:
                pass
        currentNumber.set(random.randint(start, end))
        while True:
            try:
                t = askinteger('最多允许猜几次？', '总次数', initialvalue=3)
                if t != None:
                    assert t > 0
                    totalTimes.set(t)
                    break
            except:
                pass
        already.set(0)
        button['text'] = '剩余次数：' + str(t)
        varNumber.set('0')
        entryNumber['state'] = 'normal'
        times.set(times.get() + 1)
    else:
        total = totalTimes.get()
        current = currentNumber.get()
        try:
            x = int(varNumber.get())
        except:
            showerror('抱歉', '必须输入整数')
            return
        if x == current:
            showinfo('恭喜', '猜对啦')
            button['text'] = 'Start Game'
            entryNumber['state'] = 'disabled'
            right.set(right.get() + 1)
        else:
            already.set(already.get() + 1)
            if x > current:
                showerror('抱歉', '猜的数太大了')
            else:
                showerror('抱歉', '猜的数太小了')
            if already.get() == total:
                showerror('抱歉', '游戏结束了，正确的数是：' + str(currentNumber.get()))
                button['text'] = 'Start Game'
                entryNumber['state'] = 'disabled'
            else:
                button['text'] = '剩余次数：' + str(total - already.get())


<mask token>

<mask token>


def onLeftButtonDown(event):
    root.attributes('-alpha', 0.4)
    X.set(event.x)
    Y.set(event.y)
    canMove.set(1)


<mask token>


def onLeftButtonUp(event):
    root.attributes('-alpha', 0.9)
    canMove.set(0)


<mask token>


def quit_button(event):
    but1 = tkinter.Button(root, text='退出', width=10, height=2, command=root
        .quit)
    but1.pack()


<mask token>


def buttonClick():
    if button['text'] == 'Start Game':
        while True:
            try:
                start = tkinter.simpledialog.askinteger('允许的最小整数', '最小数',
                    initialvalue=1)
                if start != None:
                    assert start > 0
                    break
            except:
                pass
        while True:
            try:
                end = askinteger('允许的最大整数', '最大数', initialvalue=11)
                if end != None:
                    assert end > 10 and end > start
                    break
            except:
                pass
        currentNumber.set(random.randint(start, end))
        while True:
            try:
                t = askinteger('最多允许猜几次？', '总次数', initialvalue=3)
                if t != None:
                    assert t > 0
                    totalTimes.set(t)
                    break
            except:
                pass
        already.set(0)
        button['text'] = '剩余次数：' + str(t)
        varNumber.set('0')
        entryNumber['state'] = 'normal'
        times.set(times.get() + 1)
    else:
        total = totalTimes.get()
        current = currentNumber.get()
        try:
            x = int(varNumber.get())
        except:
            showerror('抱歉', '必须输入整数')
            return
        if x == current:
            showinfo('恭喜', '猜对啦')
            button['text'] = 'Start Game'
            entryNumber['state'] = 'disabled'
            right.set(right.get() + 1)
        else:
            already.set(already.get() + 1)
            if x > current:
                showerror('抱歉', '猜的数太大了')
            else:
                showerror('抱歉', '猜的数太小了')
            if already.get() == total:
                showerror('抱歉', '游戏结束了，正确的数是：' + str(currentNumber.get()))
                button['text'] = 'Start Game'
                entryNumber['state'] = 'disabled'
            else:
                button['text'] = '剩余次数：' + str(total - already.get())


<mask token>


def closeWindow():
    message = '本次共玩游戏 {0} 次，猜对 {1} 次！\n欢迎下次再玩！'
    message = message.format(times.get(), right.get())
    showinfo('战绩', message)
    root.destroy()


<mask token>

<mask token>
root = tkinter.Tk()
root.attributes('-alpha', 0.9)
root.attributes('-topmost', True)
<mask token>
X = tkinter.IntVar(value=0)
Y = tkinter.IntVar(value=0)
canMove = tkinter.IntVar(value=0)
still = tkinter.IntVar(value=1)
labelDataTime = tkinter.Label(root, width=130)
labelDataTime.pack(fill=tkinter.BOTH, expand=tkinter.YES)
labelDataTime.configure(bg='yellow')


def onLeftButtonDown(event):
    root.attributes('-alpha', 0.4)
    X.set(event.x)
    Y.set(event.y)
    canMove.set(1)


labelDataTime.bind('<Button-1>', onLeftButtonDown)


def onLeftButtonUp(event):
    root.attributes('-alpha', 0.9)
    canMove.set(0)


labelDataTime.bind('<ButtonRelease-1>', onLeftButtonDown)


def quit_button(event):
    but1 = tkinter.Button(root, text='退出', width=10, height=2, command=root
        .quit)
    but1.pack()


root.title('猜数游戏')
root.geometry('720x720+500+200')
root.resizable(False, False)
varNumber = tkinter.StringVar(root, value='0')
totalTimes = tkinter.IntVar(root, value=0)
already = tkinter.IntVar(root, value=0)
currentNumber = tkinter.IntVar(root, value=0)
times = tkinter.IntVar(root, value=0)
right = tkinter.IntVar(root, value=0)
lb = tkinter.Label(root, text='请输入一个整数：')
lb.place(x=10, y=10, width=100, height=20)
entryNumber = tkinter.Entry(root, width=140, textvariable=varNumber)
entryNumber.place(x=110, y=10, width=140, height=20)
entryNumber['state'] = 'disabled'


def buttonClick():
    if button['text'] == 'Start Game':
        while True:
            try:
                start = tkinter.simpledialog.askinteger('允许的最小整数', '最小数',
                    initialvalue=1)
                if start != None:
                    assert start > 0
                    break
            except:
                pass
        while True:
            try:
                end = askinteger('允许的最大整数', '最大数', initialvalue=11)
                if end != None:
                    assert end > 10 and end > start
                    break
            except:
                pass
        currentNumber.set(random.randint(start, end))
        while True:
            try:
                t = askinteger('最多允许猜几次？', '总次数', initialvalue=3)
                if t != None:
                    assert t > 0
                    totalTimes.set(t)
                    break
            except:
                pass
        already.set(0)
        button['text'] = '剩余次数：' + str(t)
        varNumber.set('0')
        entryNumber['state'] = 'normal'
        times.set(times.get() + 1)
    else:
        total = totalTimes.get()
        current = currentNumber.get()
        try:
            x = int(varNumber.get())
        except:
            showerror('抱歉', '必须输入整数')
            return
        if x == current:
            showinfo('恭喜', '猜对啦')
            button['text'] = 'Start Game'
            entryNumber['state'] = 'disabled'
            right.set(right.get() + 1)
        else:
            already.set(already.get() + 1)
            if x > current:
                showerror('抱歉', '猜的数太大了')
            else:
                showerror('抱歉', '猜的数太小了')
            if already.get() == total:
                showerror('抱歉', '游戏结束了，正确的数是：' + str(currentNumber.get()))
                button['text'] = 'Start Game'
                entryNumber['state'] = 'disabled'
            else:
                button['text'] = '剩余次数：' + str(total - already.get())


button = tkinter.Button(root, text='Start Game', command=buttonClick)
button.place(x=10, y=40, width=250, height=20)


def closeWindow():
    message = '本次共玩游戏 {0} 次，猜对 {1} 次！\n欢迎下次再玩！'
    message = message.format(times.get(), right.get())
    showinfo('战绩', message)
    root.destroy()


root.protocol('WM_DELETE_WINDOW', closeWindow)
root.mainloop()

import random
import tkinter
from tkinter.messagebox import showerror, showinfo
from tkinter.simpledialog import askinteger
root = tkinter.Tk()
root.attributes('-alpha', 0.9)
root.attributes('-topmost', True)
import datetime
X = tkinter.IntVar(value=0)
Y = tkinter.IntVar(value=0)
canMove = tkinter.IntVar(value=0)
still = tkinter.IntVar(value=1)
labelDataTime = tkinter.Label(root, width=130)
labelDataTime.pack(fill=tkinter.BOTH, expand=tkinter.YES)
labelDataTime.configure(bg='yellow')


def onLeftButtonDown(event):
    root.attributes('-alpha', 0.4)
    X.set(event.x)
    Y.set(event.y)
    canMove.set(1)


labelDataTime.bind('<Button-1>', onLeftButtonDown)


def onLeftButtonUp(event):
    root.attributes('-alpha', 0.9)
    canMove.set(0)


labelDataTime.bind('<ButtonRelease-1>', onLeftButtonDown)


def quit_button(event):
    but1 = tkinter.Button(root, text='退出', width=10, height=2, command=root
        .quit)
    but1.pack()


root.title('猜数游戏')
root.geometry('720x720+500+200')
root.resizable(False, False)
varNumber = tkinter.StringVar(root, value='0')
totalTimes = tkinter.IntVar(root, value=0)
already = tkinter.IntVar(root, value=0)
currentNumber = tkinter.IntVar(root, value=0)
times = tkinter.IntVar(root, value=0)
right = tkinter.IntVar(root, value=0)
lb = tkinter.Label(root, text='请输入一个整数：')
lb.place(x=10, y=10, width=100, height=20)
entryNumber = tkinter.Entry(root, width=140, textvariable=varNumber)
entryNumber.place(x=110, y=10, width=140, height=20)
entryNumber['state'] = 'disabled'


def buttonClick():
    if button['text'] == 'Start Game':
        while True:
            try:
                start = tkinter.simpledialog.askinteger('允许的最小整数', '最小数',
                    initialvalue=1)
                if start != None:
                    assert start > 0
                    break
            except:
                pass
        while True:
            try:
                end = askinteger('允许的最大整数', '最大数', initialvalue=11)
                if end != None:
                    assert end > 10 and end > start
                    break
            except:
                pass
        currentNumber.set(random.randint(start, end))
        while True:
            try:
                t = askinteger('最多允许猜几次？', '总次数', initialvalue=3)
                if t != None:
                    assert t > 0
                    totalTimes.set(t)
                    break
            except:
                pass
        already.set(0)
        button['text'] = '剩余次数：' + str(t)
        varNumber.set('0')
        entryNumber['state'] = 'normal'
        times.set(times.get() + 1)
    else:
        total = totalTimes.get()
        current = currentNumber.get()
        try:
            x = int(varNumber.get())
        except:
            showerror('抱歉', '必须输入整数')
            return
        if x == current:
            showinfo('恭喜', '猜对啦')
            button['text'] = 'Start Game'
            entryNumber['state'] = 'disabled'
            right.set(right.get() + 1)
        else:
            already.set(already.get() + 1)
            if x > current:
                showerror('抱歉', '猜的数太大了')
            else:
                showerror('抱歉', '猜的数太小了')
            if already.get() == total:
                showerror('抱歉', '游戏结束了，正确的数是：' + str(currentNumber.get()))
                button['text'] = 'Start Game'
                entryNumber['state'] = 'disabled'
            else:
                button['text'] = '剩余次数：' + str(total - already.get())


button = tkinter.Button(root, text='Start Game', command=buttonClick)
button.place(x=10, y=40, width=250, height=20)


def closeWindow():
    message = '本次共玩游戏 {0} 次，猜对 {1} 次！\n欢迎下次再玩！'
    message = message.format(times.get(), right.get())
    showinfo('战绩', message)
    root.destroy()


root.protocol('WM_DELETE_WINDOW', closeWindow)
root.mainloop()

import random
import tkinter
from tkinter.messagebox import showerror,showinfo
from tkinter.simpledialog import askinteger

root = tkinter.Tk()

#root.overrideredirect(1)                 # 去除窗口边框
root.attributes('-alpha',0.9)              #半透明
root.attributes("-topmost", True)     # 永远处于顶层

#导入时间库
import datetime

X = tkinter.IntVar(value = 0)
Y = tkinter.IntVar(value = 0)
canMove = tkinter.IntVar(value = 0)
still = tkinter.IntVar(value = 1)

labelDataTime = tkinter.Label(root,width = 130)
labelDataTime.pack(fill = tkinter.BOTH,expand = tkinter.YES)
labelDataTime.configure(bg = 'yellow')

def onLeftButtonDown(event):
    root.attributes('-alpha',0.4)
    X.set(event.x)
    Y.set(event.y)
    canMove.set(1)

labelDataTime.bind('<Button-1>',onLeftButtonDown)

def onLeftButtonUp(event):
    root.attributes('-alpha',0.9)
    canMove.set(0)
    
labelDataTime.bind('<ButtonRelease-1>',onLeftButtonDown)

def quit_button(event):
    but1 = tkinter.Button(root, text = '退出', width = 10,height = 2,command = root.quit)
    but1.pack()

#窗口标题
root.title('猜数游戏')

#窗口初始大小和位置
root.geometry('720x720+500+200')


#不允许改变窗口大小
root.resizable(False, False)

#用户猜的数
varNumber = tkinter.StringVar(root, value='0')

#允许猜的总次数
totalTimes = tkinter.IntVar(root, value=0)

#已猜次数
already = tkinter.IntVar(root, value=0)

#当前生成的随机数
currentNumber = tkinter.IntVar(root, value=0)

#玩家玩游戏的总次数
times = tkinter.IntVar(root, value=0)

#玩家猜对的总次数
right = tkinter.IntVar(root, value=0)
lb = tkinter.Label(root, text='请输入一个整数：')
lb.place(x=10, y=10, width=100, height=20)

#用户猜数并输入的文本框
entryNumber = tkinter.Entry(root, width=140, textvariable=varNumber)
entryNumber.place(x=110, y=10, width=140, height=20)
#只有开始游戏以后才允许输入
entryNumber['state'] = 'disabled'

#按钮单击事件处理函数
def buttonClick():
    if button['text']=='Start Game':
    #每次游戏时允许用户自定义数值范围
    #玩家必须输入正确的数
    #最小数值
        while True:
            try:
                start = tkinter.simpledialog.askinteger('允许的最小整数',
                                                                            '最小数',
                                                                            initialvalue=1)
                if start != None:
                    assert start > 0
                    break
            except:
                pass
        #最大数值
        while True:
            try:
                end = askinteger('允许的最大整数',
                                           '最大数',
                                            initialvalue = 11)
                if end != None:
                    assert end > 10 and end > start
                    break
            except:
                pass
            
        #在用户自定义的数值范围内生成随机数
        currentNumber.set(random.randint(start, end))

         #用户自定义一共允许猜几次
         #玩家必须输入正确的整数
        while True:
            try:
                t = askinteger('最多允许猜几次？',
                                           '总次数',
                                           initialvalue=3)
                if t  != None:
                    assert t > 0
                    totalTimes.set(t)
                    break
            except:
                pass
        #已猜次数初始化为0
        already.set(0)
        button['text'] = '剩余次数：' + str(t)

        #把文本框初始化为0
        varNumber.set('0')

        #允许用户开始输入整数
        entryNumber['state'] = 'normal'

        #玩游戏的次数加1
        times.set(times.get()  +  1)
    else:
        #一共允许猜几次
        total = totalTimes.get()

         #本次游戏的正确答案
        current = currentNumber.get()

         #玩家本次猜的数
        try:
            x = int(varNumber.get())
        except:
            showerror('抱歉', '必须输入整数')
            return
        #猜对了
        if x == current:
            showinfo('恭喜', '猜对啦')
            button['text'] = 'Start Game'

             #禁用文本框
            entryNumber['state'] = 'disabled'

            #猜对的次数加1
            right.set(right.get() + 1)
        else:
            #已猜次数加1
            already.set(already.get()+1)

            if x > current:
                showerror('抱歉', '猜的数太大了')
            else:
                showerror('抱歉', '猜的数太小了')

            #可猜次数用完了
            if already.get() == total:
                showerror('抱歉', '游戏结束了，正确的数是：'+
                                                  str(currentNumber.get()))

                button['text'] = 'Start Game'
                #禁用文本框
                entryNumber['state'] = 'disabled'
            else:
                button['text'] = '剩余次数：' + str(total-already.get())

#在窗口上创建按钮，并设置事件处理函数   
button = tkinter.Button(root, text='Start Game', command=buttonClick)
button.place(x=10, y=40, width=250, height=20)
            
#关闭程序时提示战绩
def closeWindow():
    message = '本次共玩游戏 {0} 次，猜对 {1} 次！\n欢迎下次再玩！'
    message = message.format(times.get(),right.get())
    showinfo('战绩', message)
    root.destroy()
root.protocol('WM_DELETE_WINDOW', closeWindow)
      
#启动消息主循环
root.mainloop()
            
            
            
            
            
            
            
            