0
我正在使用python來創建一個鬧鐘,它提出了數學問題。但我的問題是如果用戶提供了錯誤的答案,我想繼續提問。請幫助我。我使用tkinter來創建在askyesno報警clock.But,yes和no只能是是executing.So請幫我提高代碼數學問題報警
enter code here
from tkinter import *
from tkinter import ttk
import time
import os
import sys
from tkinter import messagebox
root = Tk()
root.title("Alarm clock")
def SubmitButton():
AlarmTime= enter1.get()
Message1()
CurrentTime = time.strftime("%H:%M")
print("the alarm time is: {}".format(AlarmTime))
while AlarmTime != CurrentTime:
CurrentTime = time.strftime("%H:%M")
time.sleep(1)
x = 0
y = 0
while AlarmTime == CurrentTime:
if x == 0:
x+=1
os.system("start alarm-music.mp3")
if y<1:
label2.config(text = "Alarm music playing.....")
messagebox.showinfo(title= 'Alarm Message', message= " {}".format(enter2.get()))
while True:
if y<1:
messagebox.askquestion("answer the question in yes or no","(9^5)-1+(4|3)=18",icon='question')
y+=1
if True:
break
else:
os.system("start alarm-music.mp3")
messagebox.askyesno("answer the question","9*71=647",icon='question')
if True:
sys.close()
else:
os.system("start alarm-music.mp3")
def Message1():
AlarmTimeLable= enter1.get()
label2.config(text="the Alarm time is Counting...")
messagebox.showinfo(title = 'Alarm clock', message = 'Alarm will Ring at {}'.format(AlarmTimeLable))
alarm1 = ttk.Frame(root)
alarm1.pack()
alarm1.config(height = 200, width = 200)
alarmtime1= ttk.Label(alarm1,text = "Enter the Alarm time :")
alarmtime1.pack()
enter1 = ttk.Entry(alarm1, width = 100)
enter1.pack()
enter1.insert(3,"Please enter 24-hr format here")
AlarmMessage= ttk.Label(alarm1, text="Alarm Message:")
AlarmMessage.pack()
enter2= ttk.Entry(alarm1, width=100)
enter2.pack()
button1= ttk.Button(alarm1, text= "submit", command=SubmitButton)
button1.pack()
label2= ttk.Label(alarm1)
label2.pack()
root.mainloop()
我也想askquestion從user.So收到答案我創建了一個字典,而是在Tkinter的標籤是不讀書的問題。請幫助我那 –
@AbhiramReddy如果你需要從用戶接收字符串,你可以使用askstring()http://effbot.org/tkinterbook/tkinter-entry-dialogs.htm – neverwalkaloner
我想從randomnly問一個問題dictionary.I使用了StringVar(),但它沒有讀取字典中的值。 –