Python 导入到其他模块时使用瞬态
好了,这里转向论坛寻求帮助。我有一个导入模块dos.py的例程,我需要模块dos.py(顶级)始终位于我的主屏幕uno.py的前面。我无法暂时工作,以前我没有问题,因为我不需要始终显示的屏幕,但现在我需要我的屏幕dos.py始终位于one.py之前 这里我有一个问题,当涉及到导入模块时,我不应用transient 我把例行程序留得很短,以了解如何处理瞬态,谢谢Python 导入到其他模块时使用瞬态,python,tkinter,Python,Tkinter,好了,这里转向论坛寻求帮助。我有一个导入模块dos.py的例程,我需要模块dos.py(顶级)始终位于我的主屏幕uno.py的前面。我无法暂时工作,以前我没有问题,因为我不需要始终显示的屏幕,但现在我需要我的屏幕dos.py始终位于one.py之前 这里我有一个问题,当涉及到导入模块时,我不应用transient 我把例行程序留得很短,以了解如何处理瞬态,谢谢 # uno.py import tkinter as tk class PRUEBA: def __init__
# uno.py
import tkinter as tk
class PRUEBA:
def __init__(self):
ventana_principal = tk.Tk()
ventana_principal.geometry ("600x600")
ventana_principal.config (bg="blue")
ventana_principal.title ("PANTALLA PRINCIPAL")
def importar():
from dos import toplevel
toplevel()
boton = tk.Button (ventana_principal , text = "boton" , command = importar)
boton.pack ( )
ventana_principal.mainloop()
PRUEBAS = PRUEBA ()
**模块dos.py
#dos.py
import tkinter as tk
class toplevel:
def __init__(self):
secundario = tk.Toplevel ()
secundario.geometry ("150x40+190+100")
secundario.resizable(0,0)
secundario.transient(self.master) """ Here I have the problem not to apply transient
when it comes to importing modules """
抱歉您的代码将引发异常: AttributeError:“toplevel”对象没有属性“master” 行
secundario.transient(self.master)
应改为secundario.transient(secundario.master)
但是,toplevel
的实例是无用的,因为它是一个局部变量,您以后无法访问secundario
建议使toplevel
继承自tk.toplevel
:
class toplevel(tk.Toplevel):
def __init__(self, parent, *args, **kw):
super().__init__(parent, *args, **kw)
self.geometry("150x40+190+100")
self.resizable(0, 0)
self.transient(parent)
然后像这样创建它:
top = toplevel(ventana_principal)
您的代码将引发异常: AttributeError:“toplevel”对象没有属性“master” 行
secundario.transient(self.master)
应改为secundario.transient(secundario.master)
但是,toplevel
的实例是无用的,因为它是一个局部变量,您以后无法访问secundario
建议使toplevel
继承自tk.toplevel
:
class toplevel(tk.Toplevel):
def __init__(self, parent, *args, **kw):
super().__init__(parent, *args, **kw)
self.geometry("150x40+190+100")
self.resizable(0, 0)
self.transient(parent)
然后像这样创建它:
top = toplevel(ventana_principal)
什么是原则?是否应该改为“secundario”?对不起,secundario是什么?是否应改为
secundario
?对不起,是secundario吗?如果答案有帮助,请接受,因为它用于你的另一个问题。如果答案有帮助,请接受,因为它用于你的另一个问题