Python display variable with tkinter inside a method

后端 未结 2 1038
既然无缘
既然无缘 2021-01-25 10:42

The program I just wrote is my playground for finding out how Tkinter works.
My question is how do I display my variable \"timelabel\" as a Label.

I allready made a

2条回答
  •  情话喂你
    2021-01-25 11:07

    You should have written an MCVE so that one can test your code, especially that things are missing (such as Presstoshowtextandpic()).

    When reading the rest of your code, I think you need to read about variable classes and modify Clockupdate() as follows:

    def Clockupdate(time):
        timelabel = StringVar() # modified
        timelabel.set(time) # added
        timerefresher = Label(root, textvariable=timelabel.get()) #modified
        timerefresher.pack()
    

    P.S. You should write clock_update() instead of Clockupdate()

提交回复
热议问题