【问题标题】:Python Tkinter or ttk, Send text to other toplevel windowPython Tkinter 或 ttk,将文本发送到其他顶层窗口
【发布时间】:2016-11-02 05:40:02
【问题描述】:

我在开发 Python ttk 代码期间使用单独的顶级窗口,并希望从根目录发送消息以调试顶级窗口。

这是一些伪代码

from Tkinter import *
import ttk
from MyFunctions import *    # some code I wrote (see below)
root = Tk()
SetupMyFunct(root)           # see below
de_bug = Toplevel(root)
dbug_frame = Frame(de_bug).grid()
debug_string1 = StringVar()
debug1_window = ttk.Label(dbug_frame, textvariable = debug_string1).grid()
root.mainloop()

在我的 MyFunctions.py 中:

from Tkinter import *
import ttk
def SetupMyFunct(root):
    f = ttk.Frame(root).grid()
    w = Frame(f).grid()

此时我想发送一些文本以在 de_bug 窗口中自动更新,但我真的不知道从哪里开始。

请帮忙? 标记。

【问题讨论】:

    标签: python tkinter toplevel


    【解决方案1】:

    链接几何管理方法可防止您保留对这些小部件的引用,因为这些方法返回 None 以存储在这些变量中。别那样做。这将允许你做一些事情,比如使用你的小部件的引用。具体来说,您可以将dbug_frame 指定为debug1_window 小部件的父对象。

    from Tkinter import *
    import ttk
    from MyFunctions import *
    root = Tk()
    f,w = SetupMyFunct(root)
    de_bug = Toplevel(root)
    dbug_frame = Frame(de_bug)
    dbug_frame.grid()
    debug_string1 = StringVar()
    debug1_window = ttk.Label(dbug_frame, textvariable=debug_string1)
    debug1_window.grid()
    root.mainloop()
    

     

    from Tkinter import *
    import ttk
    def SetupMyFunct(root):
        f = ttk.Frame(root)
        f.grid()
        w = Frame(f)
        w.grid()
        return f,w
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多