0
我有一个python脚本和一个文本文件,其中包含像18:59,19:00,19:02等等的时间(字符串)列表...每个都在不同的行中。我想在文件中的时间是当前时间的情况下更改tkinter中标签的颜色。Tkinter窗口在运行时关闭
问题是tkinter窗口一旦打开就会关闭,然后一旦一切完成就会再次打开。我尝试使用update_idletasks。但是这并没有改变任何东西。下面是所需的代码结构:
class gui(Frame):
def __init__(self, parent, txt2, index):
Frame.__init__(self,parent,background="white")
self.parent = parent
self.txt2 = txt2
self.index = index
self.initUI()
self.initChange()
def initUI(self)
#initial window with white color label
def initChange(self)
while(last line hasnt reached):
if(current time = file time)
#line for changing label color and self.index++
self.parent.update_idletasks()
sleep(30)
main()
#call all the functions required and root, txt file and initial index is passed as arguments for gui functions
由于我被要求忍受我已经使用了所有的功能,我这样做,但我忽略了细节。代码太长。
def dataextract(xlsheet):
#take data from xlsheet
#called only once in the main() function
def fileio(x, txt1)
#Write the time list after doing some operations
#based on data from xlsheet
def main():
x = datextract(xlsheet)
fileio(x, txt)
print "File IO competed..."
root = Tk()
app = gui(root, txt2, 0)
root.mainloop()
if __name__ == "__main__":
main()
什么是'main()'?而所有的功能/线路都被遗漏了。没有看到这些,我们不禁感慨。 – SneakyTurtle
你有'主循环'吗? – Pythonista
@Pythonista是的,我做 – Jake259