使用按钮在Tkinter窗口中刷新代码 [英] Refreshing code in Tkinter window with button

查看:547
本文介绍了使用按钮在Tkinter窗口中刷新代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是99%这是不可能的,因为python是第一个字节编译然后可能打开了Tk窗口,但我想知道是否有任何情况下,添加一个按钮来刷新您的tk应用程序在您保存后的位置它实际上写的应用程序?

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.

某些...

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()


推荐答案

哇我想出来了我做了两个电源。一个导入,另一个刷新。

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

这里你去:

#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() 

这篇关于使用按钮在Tkinter窗口中刷新代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆