import tkinter as tk
from random import randint
def get():
global count_number
number = guess.get()
if number < random_number:
count_number +=1
count.set(count_number)
hint.set("Higher!")
root.after(1000, clear_hint)
elif number > random_number:
count_number +=1
count.set(count_number)
hint.set("Lower!")
root.after(1000, clear_hint)
else:
hint.set("Well guessed!")
count_number +=1
count.set(count_number)
root.after(5000, setup)
def setup():
global random_number
global count_number
random_number = randint(1, 100)
guess.set(0)
count.set(0)
hint.set("Start Guessing!")
root.after(5000, clear_hint)
def clear_hint():
hint.set("")
root = tk.Tk()
root.geometry("300x60")
root.title("数当てゲーム(1-100)")
hint = tk.StringVar()
guess = tk.IntVar()
count=tk.IntVar()
random_number = 0
count_number=0
tk.Entry(textvariable=guess).grid(column=0, row=0)
tk.Button(root, text="Guess", command=get).grid(column=1, row=0)
tk.Label(root, textvariable=hint).grid(column=0, row=1)
tk.Label(root, textvariable=count).grid(column=2, row=0)
setup()
コメント
コメントを投稿