【问题标题】:How to add text to a Toplevel window如何将文本添加到顶层窗口
【发布时间】:2017-02-13 19:19:51
【问题描述】:

我想在单击“x”和“x1”按钮时打开的窗口中添加文本。但我想不通。

import tkinter as tk
from tkinter import *

def create_window():
    window = tk.Toplevel(root)

root = tk.Tk()
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))


b = tk.Button(root, text="x", command=create_window)
b.pack(side=TOP, anchor=W, fill=BOTH, expand=YES)

b1 = tk.Button(root, text="x1", command=create_window)
b1.pack(side=TOP, anchor=W, fill=BOTH, expand=YES)

root.mainloop()

【问题讨论】:

  • 使用Label 小部件。
  • 谢谢。你能给我举个小例子吗?
  • 互联网上有数百万个使用标签小部件的例子。

标签: python text tkinter toplevel


【解决方案1】:

Bryan 的意思是这样的:

def create_window():
    window = tk.Toplevel(root)
    tk.Label(window, text='your text').pack(padx=30, pady=30)

正如他所说,在发布之前阅读了一些示例。看来你不知道什么是 Toplevel....

【讨论】:

  • 非常感谢。我是 Python 新手。我搜索了很多网站,但找不到像您刚刚写的那样的内容。
  • 顶级窗口是出现在根窗口之上的窗口。所以你必须在上面放置小部件(标签、按钮和其他)才能看到一些东西
  • 再次感谢!在你帮助我之后,我终于创建了我需要的程序。
猜你喜欢
  • 2019-11-16
  • 1970-01-01
  • 1970-01-01
  • 2019-10-06
  • 2019-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多