from tkinter import*
import random
class Application(Frame):
def __init__(self,master):
super(Application,self).__init__(master)
self.grid()
self.create_widgets()
def create_widgets(self):
Label(self,
text="Попробуй угадать число"
).grid(row=1,column=0,sticky =W)
Label(self,
text="ваше число"
).grid(row=2,column=0,sticky=W)
self.number_ent = Entry(self)
self.number_ent.grid(row=2,column=1,sticky=W)
Button(self,
text="Проверить число",
command = self.check_number
).grid(row=3,column=0,sticky=W)
self.sq = Text(self, width = 100, height = 10,wrap=WORD)
self.sq.grid(row=4,column=0,columnspan=3)
def check_number(self):
the_number = random.randint(1,100)
tries = 1
guess = int(self.number_ent.get())
if guess == the_number:
x = "Good job, you get it for ", tries,"tries"
self.sq.insert(0.0,x)
elif guess > the_number:
x = "less\n"
tries +=1
self.sq.insert(0.0,x)
elif guess < the_number:
x = "more\n"
tries +=1
self.sq.insert(0.0,x)
root = Tk()
root.title("Try to guess")
app = Application(root)
root.mainloop()
import random
class Application(Frame):
def __init__(self,master):
super(Application,self).__init__(master)
self.grid()
self.create_widgets()
def create_widgets(self):
Label(self,
text="Попробуй угадать число"
).grid(row=1,column=0,sticky =W)
Label(self,
text="ваше число"
).grid(row=2,column=0,sticky=W)
self.number_ent = Entry(self)
self.number_ent.grid(row=2,column=1,sticky=W)
Button(self,
text="Проверить число",
command = self.check_number
).grid(row=3,column=0,sticky=W)
self.sq = Text(self, width = 100, height = 10,wrap=WORD)
self.sq.grid(row=4,column=0,columnspan=3)
def check_number(self):
the_number = random.randint(1,100)
tries = 1
guess = int(self.number_ent.get())
if guess == the_number:
x = "Good job, you get it for ", tries,"tries"
self.sq.insert(0.0,x)
elif guess > the_number:
x = "less\n"
tries +=1
self.sq.insert(0.0,x)
elif guess < the_number:
x = "more\n"
tries +=1
self.sq.insert(0.0,x)
root = Tk()
root.title("Try to guess")
app = Application(root)
root.mainloop()