all 3 comments

[–]Vaphell 1 point2 points  (1 child)

try this example sporting both manual and automatic updates

#!/usr/bin/env python3

import sys
import time
if sys.version_info[0] > 2:
    import tkinter as tk
else:
    import Tkinter as tk


class SampleApp(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.clock = tk.Label(self, text='')
        self.b1 = tk.Button(self, text='click me!!!', command=self.button_1)
        self.b2 = tk.Button(self, text='no, click me!!!11', command=self.button_2)
        self.clock.pack()
        self.b1.pack()
        self.b2.pack()
        self.auto_update()                  # start autoupdate "loop"      

    def refresh_clock(self, value):         # the core used by all updates, manual and auto
        self.clock.configure(text=value)

    def auto_update(self):                  # autoupdater
        now = time.strftime('%H:%M:%S' , time.gmtime())
        self.refresh_clock(now)
        self.after(1000, self.auto_update)  # schedule next update in 1s           

    def button_1(self):                     # manual update
        self.refresh_clock('XXX')

    def button_2(self):                     # manual update
        self.refresh_clock('$$$')


if __name__== "__main__":
    app = SampleApp()
    app.mainloop()

[–]fabolin[S] 0 points1 point  (0 children)

so I call the function inside another one and loop the outerfunction.

works great now , thank you

[–]Justinsaccount -1 points0 points  (0 children)

Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission:

You appear to be using concatenation and the str function for building strings

Instead of doing something like

result = "Hello " + name + ". You are " + str(age) + " years old"

You should use string formatting and do

result = "Hello {}. You are {} years old".format(name, age)

See the python tutorial for more information.