|  | 
 
 
 楼主|
发表于 2018-4-5 11:34:11
|
显示全部楼层 
| from tkinter import * import sys
 import random
 
 def choiceboundary():
 
 def gameing():
 def conutinue():
 
 def game1():
 a = random.randint(0,11)
 b = int(e.get())
 c = int(0)
 d = int(2)
 while (b != a) and (c < d):
 if b > a:
 root = Tk()
 root.title('重新输入')
 Label(root,text = '太大了!重新输入:').grid(row = 0)
 e = Entry(root)
 e.grid(row = 1,column = 0,padx = 10,pady = 5)
 theButton = Button(root,text = '确认',width = 10,command = game1).grid(row = 2,column = 2,sticky = W,padx = 10,pady = 5)
 c += 1
 
 mainloop()
 if b < a:
 root = Tk()
 root.title('重新输入')
 Label(root,text = '太小了!重新输入:').grid(row = 0)
 e = Entry(root)
 e.grid(row = 1,column = 0,padx = 10,pady = 5)
 theButton = Button(root,text = '确认',width = 10,command = game1).grid(row = 2,column = 2,sticky = W,padx = 10,pady = 5)
 c += 1
 mainloop()
 
 if (b == a) and (c < d):
 root = Tk()
 textLabel = Label(root,text = '猜对了!')
 textLabel.pack()
 mainloop()
 if (c == d):
 root = Tk()
 textLabel = Label(root,text = '没有机会了!')
 textLabel.pask()
 mainloop()
 
 def game2():
 f = random.randint(0,31)
 g = int(e.get())
 h = int(0)
 i = int(3)
 while (g != f) and (h<i):
 if g>f:
 root = Tk()
 root.title('重新输入')
 Label(root,text = '太大了!重新输入:'.grid(row = 0))
 e = Entry(root)
 e.grid(row = 1,column = 1,padx = 10,pady = 5)
 mainloop()
 if g<f:
 root = Tk()
 root.title('重新输入')
 Label(root,text = '太小了!重新输入:'.grid(row = 0))
 e = Entry(root)
 e.grid(row = 1,column = 1,padx = 10,pady = 5)
 mainloop()
 h += 1
 if (g == f) and (h<i):
 root = Tk()
 textLabel = Label(root,text = '猜对了!')
 textLabel.pack()
 mainloop()
 if (h == i):
 root = Tk()
 textLabel = Label(root,text = '没有机会了!')
 textLabel.pask()
 mainloop()
 
 def game3():
 j = random.randint(0,51)
 k = int(e.get())
 l = int(0)
 o = int(5)
 while (k != j) and (l<o):
 if k>j:
 root = Tk()
 root.title('重新输入')
 Label(root,text = '太大了!重新输入:'.grid(row = 0))
 e = Entry(root)
 e.grid(row = 1,column = 1,padx = 10,pady = 5)
 mainloop()
 if k<j:
 root = Tk()
 root.title('重新输入')
 Label(root,text = '太小了!重新输入:'.grid(row = 0))
 e = Entry(root)
 e.grid(row = 1,column = 1,padx = 10,pady = 5)
 mainloop()
 l += 1
 if (k == j) and (l<o):
 root = Tk()
 textLabel = Label(root,text = '猜对了!')
 textLabel.pack()
 mainloop()
 if (l == o):
 root = Tk()
 textLabel = Label(root,text = '没有机会了!')
 textLabel.pask()
 mainloop()
 
 
 if p1:
 game1()
 if p2:
 game2()
 if p3:
 game3()
 
 
 root = Tk()
 root.title('游戏进行中')
 Label(root,text = '输入你猜的数字:').grid(row = 0)
 e = Entry(root)
 e.grid(row = 0,column = 1,padx = 10,pady = 5)
 theButton = Button(root,text = '确认',width = 10,command = conutinue).grid(row = 2,column = 0,sticky = W,padx = 10,pady = 5)
 theButton = Button(root,text = '退出',width = 10,command = root.quit).grid(row = 2,column = 1,sticky = E,padx = 10,pady = 5)
 global w
 w = e.get()
 
 mainloop()
 
 
 
 
 
 root = Tk()
 root.title('猜数字游戏')
 group = LabelFrame(root,text = '选择难度',padx = 30,pady = 30)
 group.pack(padx = 50,pady = 50)
 v = IntVar()
 p1 = Radiobutton(group,text = '简单(0-10,2次机会)',variable = v,value = 1,indicatoron = False,command = gameing)
 p1.pack(fill = X)
 p2 = Radiobutton(group,text = '中等(0-30,3次机会)',variable = v,value = 2,indicatoron = False,command = gameing)
 p2.pack(fill = X)
 p3 = Radiobutton(group,text = '困难(0-50,5次机会)',variable = v,value = 3,indicatoron = False,command = gameing)
 p3.pack(fill = X)
 
 mainloop()
 
 
 
 
 root = Tk()
 
 root.title('XNgame')
 photo = PhotoImage(file = 'XG.gif')
 theLabel = Label(root,
 text = '欢迎使用XNgame!',
 justify = LEFT,
 image = photo,
 compound = CENTER,
 font = ('微软雅黑',20),
 fg='black'
 )
 theLabel.pack()
 theButton = Button(root,text = '进入',command = choiceboundary)
 theButton.pack()
 
 mainloop()
 
 | 
 |