【发布时间】:2017-11-18 23:43:29
【问题描述】:
我想创建一个 GUI 模块,我可以在我的主程序中导入它,而不必在那里导入 tkinter,让模块处理所有事情。这是我想象它可能起作用的方式:
main.py
import gui as g
def update():
#Update the GUI with new Data from this main program
GUI = g.gui()
gui.after(1000, update)
gui.mainloop()
gui.py
import tkinter as tk
class viewer(tk.Frame):
#Some variables
def __init__(self, parent):
tk.Frame.__init(self, parent)
self.parent = parent
self.initialize(400, 100)
def initialize(self, width, height):
#Initialize some widgets, place them on grid, etc
def start(self):
#Do some other stuff, make a main window, configurations, etc
print('Started!')
编辑:“不要征求意见” 我该如何完成这项工作?
import tkinter as tk
import gui as g
root = tk.Tk()
GUI = g.gui(root)
GUI.after(1000, update)
GUI.mainloop()
以上是我不想要的。
【问题讨论】:
-
你在征求意见,这与这里无关。
-
顺便说一句:模块 turtle、graphics.py 和 EasyGui 使用
tkinter并且您不必导入tkinter- 这样您就可以看到它是如何工作的。 -
上面的例子很好,虽然对我的理解水平来说太复杂了。我通过 gui 模块中的简单方法修复了它,该方法启动 gui 并返回所述对象
标签: python python-3.x user-interface tkinter