我想从函数window_update设置字符串变量。我想在该功能上运行滚动消息和时钟。但是self.update()无法正常工作,我该怎么办?可能是一个愚蠢的错误。请帮忙。
from Tkinter import *
import Tkinter,MySQLdb,tkFont,datetime,time,tkMessageBox,socket,os
from datetime import datetime
from threading import Thread
class Master(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.initialize()
def window_update(self):
msg = "My scrolling message "
while True:
msg=msg[1:]+msg[0]
self.my_tickers.set(msg)
self.my_clock.set(time.strftime("%H:%M"))
self.my_date.set(datetime.now().strftime("%d-%m-%Y"))
print "updated"
self.update()
time.sleep(1)
def mainwindow(self):
while True:
main function work done here
def initialize(self):
self.grid()
self.my_clock = StringVar(self)
self.my_date = StringVar(self)
self.my_tickers = StringVar(self)
self.my_clock.set("00:00")
self.my_date.set("00/00/0000")
self.my_tickers.set("welcome.")
labeltickers=Label(self,textvariable = self.my_tickers,height=1,width=32, relief=RAISED,\
fg="white",bg="purple",font=('Sans','38','bold'))
labeltickers.grid(column=0,columnspan=7,row=8,sticky='NSEW')
clock = Label( self, textvariable = self.my_clock, relief=RAISED,bg="dark olive green",fg="white",\
font=('Sans','60','bold'),justify = "center",width=5,pady=20,anchor=SE)
clock.grid(column=5,columnspan=2,row=0,rowspan=2,sticky='SE')
date_clock = Label( self, textvariable = self.my_date, relief=SUNKEN,bg="dark olive green",fg="white",\
font=('Sans','18','bold'),justify = "right",width=9)
date_clock.grid(column=6,columnspan=2,row=1,sticky='SW')
self.after(10,self.mainwindow)
if __name__ == "__main__":
window = Master(None)
window.title("Test window")
window.configure(background="AntiqueWhite2")
window.mainloop()
此程序从window_update打印更新的消息一次,之后没有错误消息也没有更新。由于self.update()命令而可能出错。我认为这可能是由于可访问性问题引起的错误,但我无法解决。