1

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()
jwillis0720
  • 4,329
  • 8
  • 41
  • 74

2 Answers2

2

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() 
jwillis0720
  • 4,329
  • 8
  • 41
  • 74
  • Then anytime you change the file and save it, hit the refresh button and it will load a new window and destroy the other one – jwillis0720 Nov 07 '13 at 01:24
  • You said "refresh the frame instead of closing and starting a new instance" but now you are destroying the `Tk` instance and then creating a new instance and new widgets inside it and even launching a new tcl interpreter. – Stop harming Monica Dec 02 '16 at 12:17
1

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

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179