Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Tkinter-从帮助文件打开GUI窗口_Python_User Interface_Instance_Parent_Self - Fatal编程技术网

Python 2.7 Tkinter-从帮助文件打开GUI窗口

Python 2.7 Tkinter-从帮助文件打开GUI窗口,python,user-interface,instance,parent,self,Python,User Interface,Instance,Parent,Self,我有两个文件。GUI.py和Helper.py。 我把我所有的逻辑都放在Helper.py中 在Helper.py中,我导入了GUI,因为我想在Helper中发生某些事情时从GUI调用一个窗口。到目前为止,这是一个好办法吗 现在在GUI.py中,我有了类GUIFrame 还有你自己,父母 我要调用的函数在init中。那么如何从helper文件调用它呢 到目前为止,我在Helper.py中尝试了这个 导入GUI GUI=GUI.GUI 但我得到了一个错误: TypeError:init只接受给定的

我有两个文件。GUI.py和Helper.py。 我把我所有的逻辑都放在Helper.py中

在Helper.py中,我导入了GUI,因为我想在Helper中发生某些事情时从GUI调用一个窗口。到目前为止,这是一个好办法吗

现在在GUI.py中,我有了类GUIFrame 还有你自己,父母

我要调用的函数在init中。那么如何从helper文件调用它呢

到目前为止,我在Helper.py中尝试了这个 导入GUI GUI=GUI.GUI

但我得到了一个错误: TypeError:init只接受给定的2个参数1

我做错了什么


我试着把self放在那里,我得到了我的类实例没有属性“tk”

我想你的代码是这样的:

GUI.py

因此uuu init_uuuu方法中的父对象只是Tk的一个对象,如果您想创建GUI并在其他python脚本(如Helper.py)中显示它,请使用以下代码:

Helper.py


那么,init方法中的父级是什么?Tkinter.Tk?老实说,我不太确定。最上面是Tkinter import*中的类,然后是类GUIFrame:def uu init u self,parent:Frame.u init u self,parent self.parent=parent我想你误解了我一点。我想调用一个从Helper.py到GUI.py的窗口。换句话说,我想这样做:在Helper中打开GUI.beautifulChartWindow,让它在GUI中打开。pyGUI.py是我保存所有GUI内容的地方,Helper是我所有的逻辑,但我想这样,如果逻辑中发生了什么,它就会调用GUI中的窗口。@Richard,我想我没有误解。请再次查看我的帖子。我刚刚修改了它。当我这样做时,我得到RuntimeError:主线程不在主循环中,我不知道。在GUI.py中,我有线程,因此一个线程不断地检查helper中的函数,以查看是否调用了其中任何一个。此外,一个全新的窗口打开,我也不希望这样。一张空白的。。。美丽的窗户永远不会打开。
class GUI(Frame):
    def __init__(self,parent):
        Frame.__init__(self,parent)
        self.parent = parent
        self.addQuitBtn()
        self.pack()
        mainloop()

    def addQuitBtn(self):
        quit = Button(self.parent,text='QUIT',command=self.parent.quit,activeforeground='white',activebackground='red')
        quit.pack()

    def beautifulChartWindow(self):
        pass
import GUI
from Tkinter import *

root = Tk()
root.geometry('600x400')

#What you have been stucked is how to create the GUI object.Just do it like this
#GUI = GUI.GUI(root)

#Once you got the GUI object, you can call the methods in GUI.py like this(here in file Helper.py)

#So you need to pass the GUI object that you have created before(Maybe just in the file GUI.py? You should call this method like Helper.myBeautifulChartWindow(GUI).This GUI is the object GUI,not the module GUI nor class GUI)
def myBeautifulChartWindow(MyGUIObject):
    MyGUIObject.beautifulChartWindow()