Question

I'm 99% this isn't possible since python is first byte compiled then probably opens the Tk windows, but I'm wondering if there is any circumstance to add a button to refresh your tk app in place after you save the app its actually written in?

You can imagine after updating padding or some minor attribute it would be so cool to just hit the button to refresh the frame instead of closing and starting a new instance.

something...

class myapp()
 def __init___(self,root):
   self.root = root
   main_menu = ttk.Frame(self.root)
   ttk.Button(main_menu,text="Refresh",command=lambda root=self.root:refresh_me(root)))
 def refresh_me(self,root):
     #refresh the window I'm in somehow...
root = Tkinter.Tk()
myapp = myapp(root)
root.mainloop()
Was it helpful?

Solution

Wow I figured it out. I made two mains. One to import and the other to refresh.

Here you go:

#name of file is python_script.py

class myapp()
 def __init___(self,root):
   self.root = root
   main_menu = ttk.Frame(self.root)
   ttk.Button(main_menu,text="REFRESH",command=lambda self=self:self._update())

 def _update(self):
   import python_script
   python_script.main_refresh(self.root,python_script)

def main_refresh(root,python_script):
   reload(python_script)
   root.destroy()
   python_script.main()

def main():
   root = Tkinter.Tk()
   myapp = myapp(root)
   root.mainloop()

if __name__ == '__main__':
   main() 

OTHER TIPS

this doesnt exactly answer the question but does provide a path to your stated goal

first easy_install q

then

class myapp()
 def __init___(self,root):
   self.root = root
   main_menu = ttk.Frame(self.root)
   ttk.Button(main_menu,text="Refresh",command=lambda root=self.root:refresh_me(root)))
 def shell_me(self,root):
     #refresh the window I'm in somehow...
     import q
     q.d()

at which point a shell opens and you can do something like

>>> myapp.padding = "10px" #or whatever you are trying to modify
>>> exit()

your app will then resume with the updated params.

there are other options like pycrust that open an interactive shell that may not block the main loop and probably include some additional functionality ... but q.d() is in my experience the easiest one to just toss up

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top