我正在编写一个代码来创建一个时间日历,由于某些原因,开始和结束的时间刻度盘是相互镜像的。我已经检查了所有的东西,但是我看不出代码为什么会做这样的事情
这是密码
from Tkinter import *
import math
Master = Tk()
def Value_Check():
Start_Hours = eval(Starting_Hours.get())
Start_Min = eval(Starting_Minutes.get())
End_Hours = eval(Ending_Hours.get())
End_Min = eval(Ending_Minutes.get())
Start_Time_Window = ((Start_Hours*60)+ Start_Min)
End_Time_Window = ((End_Hours*60)+ End_Min)
Total_Window = (Start_Time_Window - End_Time_Window)
Window_Hours = math.floor(Total_Window/60)
Window_Minutes = (Total_Window - Window_Hours)
print "You have a ", Window_Hours, "Hours and", Window_Minutes, "minute window to test"
Frame_Start_Window= Frame(Master)
Frame_Start_Window.pack()
#Setting the starting time of the testing window
Start_Time_Frame = Frame(Master)
Start_Time_Frame.pack( side = BOTTOM )
Starting_Title = Label(Frame_Start_Window, text = "When can you start testing? ")
Starting_Title.pack()
Starting_Hours = Spinbox(Frame_Start_Window, text = "Hour", from_ = 1, to = 24, wrap =True, width = 2, command = Value_Check)
Starting_Hours.pack(side = LEFT)
Collen_Title = Label(Frame_Start_Window, text = ":")
Collen_Title.pack(side = LEFT)
Starting_Minutes = Spinbox(Frame_Start_Window, text = "Minutes", from_ = 0, to = 59, wrap =True, width = 2, command = Value_Check)
Starting_Minutes.pack(side = LEFT)
#The end half of the testing window:
Frame_End_Window= Frame(Master)
Frame_End_Window.pack()
#Setting the starting time of the testing window:
End_Title = Label(Frame_End_Window, text = "What time do you HAVE to stop testing?")
End_Title.pack()
Ending_Hours = Spinbox(Frame_End_Window, text = "Hour", from_ = 1, to = 24, wrap =True, width = 2, command = Value_Check)
Ending_Hours.pack(side = LEFT)
Collen2_Title = Label(Frame_End_Window, text = ":")
Collen2_Title.pack(side = LEFT)
Ending_Minutes = Spinbox(Frame_End_Window, text = "Minutes", from_ = 0, to = 59, wrap =True, width = 2, command = Value_Check)
Ending_Minutes.pack(side = LEFT)
#Where the answer from the Test_Calculator button is displayed:
Results_Screen = Text(Master, height=2, width=65)
Results_Screen.pack()
Data_Reset = Button (Master, text = "Reset Values", command = Value_Check)
Data_Reset.pack()
mainloop()
答案是
Spinbox
没有text
配置参数:它有textvariable
,它接受text
作为缩写。这意味着您有两个独立的Spinbox小部件,它们都使用textvariable
的Hour
和两个独立的Spinbox小部件,它们都使用textvariable
的Minute
。textvariable
设置告诉Spinbox将Spinbox的内容链接到指定变量的内容;无论何时Spinbox更改,命名变量都将更改;无论何时命名变量更改,Spinbox都将更改。因此,更改一个Spinbox中的值,它会更新变量,而变量又会更新另一个Spinbox相关问题 更多 >
编程相关推荐