import tkinter as tk
import tkinter.messagebox as tmsg
import random
def ButtonClick():
#a=[random.randint(1,9),random.randint(1,9),random.randint(1,9),random.randint(1,9),]
b=editbox_1.get()
if (len(b)!=4):
tmsg.showerror("錯誤","請重新輸入")
else:
kazuok=True
for i in range(4):
if (b[i]>"9" or b[i]<"0"):
tmsg.showerror("錯誤","請重新輸入")
kazuok=False
break
if kazuok:
tmsg.showinfo("你輸入的文字",b)
root=tk.Tk()
root.title("猜數字遊戲")
root.geometry("400x200")
label_1=tk.Label(root,text="請輸入數字",font=("Helvetica",14))
label_1.place(x=20,y=20)
editbox_1=tk.Entry(width=4,font=("Helvetica",14))
editbox_1.place(x=150,y=20)
button_1=tk.Button(root,text="確認",font=("Helvetica",14),command=ButtonClick)
button_1.place(x=150,y=60)
root.mainloop()
沒有留言:
張貼留言