Created
May 17, 2018 15:59
-
-
Save jangia/beae0917f8a6aa18a9a7bc1a2bf4ebfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Tkinter | |
import random | |
import tkMessageBox | |
def check_guess(): | |
if int(guess.get()) == secret: | |
result_text = 'CORRECT!' | |
elif int(guess.get()) > secret: | |
result_text = 'WRONG! Too high!' | |
else: | |
result_text = 'WRONG! Too low!' | |
result_text_var.set(result_text) | |
tkMessageBox.showinfo('Result', result_text) | |
window = Tkinter.Tk() | |
result_text_var = Tkinter.DoubleVar(window, value='Nisi se ugibal') | |
secret = random.randint(1, 100) | |
greeting = Tkinter.Label(window, text='Guess secret number!') | |
greeting.pack() | |
guess = Tkinter.Entry(window) | |
guess.pack() | |
submit = Tkinter.Button(window, text='Submit', command=check_guess) | |
submit.pack() | |
result_text_label = Tkinter.Label(window, textvariable=result_text_var) | |
result_text_label.pack() | |
# potrdi vnos z Enter tipko | |
window.bind('<Return>', lambda _: check_guess()) | |
window.mainloop() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Tkinter | |
import random | |
class MyApp: | |
def __init__(self): | |
self.window = Tkinter.Tk() | |
self.result_text_var = Tkinter.DoubleVar(self.window, value='Nisi se ugibal') | |
self.secret = random.randint(1, 100) | |
self.greeting = Tkinter.Label(self.window, text='Guess secret number!') | |
self.greeting.pack() | |
self.guess = Tkinter.Entry(self.window) | |
self.guess.pack() | |
self.submit = Tkinter.Button(self.window, text='Submit', command=self.check_guess) | |
self.submit.pack() | |
self.result_text_label = Tkinter.Label(self.window, textvariable=self.result_text_var) | |
self.result_text_label.pack() | |
# potrdi vnos z Enter tipko | |
self.window.bind('<Return>', lambda _: self.check_guess()) | |
def run(self): | |
self.window.mainloop() | |
def check_guess(self): | |
if int(self.guess.get()) == self.secret: | |
result_text = 'CORRECT!' | |
self.secret = random.randint(1, 100) | |
elif int(self.guess.get()) > self.secret: | |
result_text = 'WRONG! Too high!' | |
else: | |
result_text = 'WRONG! Too low!' | |
self.result_text_var.set(result_text) | |
app = MyApp() | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment