【问题标题】:I need a way to add a non-button title using tkinter in python我需要一种在 python 中使用 tkinter 添加非按钮标题的方法
【发布时间】:2017-02-07 14:32:17
【问题描述】:

到目前为止我的代码是这样的:

import tkinter

def hello():
    a = tkinter.Button(text ="what is this", padx = 10, pady = 10)
    a.pack()
    c = tkinter.Button(text ="what do you want", padx = 10, pady = 10)
    c.pack()

b = tkinter.Button(text = "Welcome to the interface. click to get started", command = hello, padx = 10, pady = 10)
b.pack()

我想单击第一个按钮并让它显示下一个按钮,上面有一些文字。我尝试 print 作为最后的手段,但它进入了 shell,就像我想的那样。似乎没有任何效果。我看到了一些关于“text_widget”的东西,但我无法让它工作。

【问题讨论】:

  • 每次点击时,您是想在上面添加新行还是只添加一行文本,根据点击的按钮进行更改?
  • 所以是Label 而不是按钮?

标签: python text tkinter


【解决方案1】:

您要使用的是Label。标签是一种将文本呈现到 tk 窗口上的方法。例如,您使用的是c = tkinter.Button(text ="what do you want", padx = 10, pady = 10)。要将其创建为文本,您应该使用c = tkinter.Label(text ="what do you want", padx = 10, pady = 10)

此外,这个问题提供的关于您想要做什么的信息很少,因此很难显示您的要求。

如果你想要一个上面有文字的按钮,你应该使用:

examplelabel = tkinter.Label(text = "Example Text")
examplelabel.pack()
examplebutton = tkinter.Button(...)
examplebutton.pack()

对不起,如果这个答案很糟糕,我对这种类型的 python 不太擅长。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 1970-01-01
    • 2020-09-30
    • 2021-04-21
    • 1970-01-01
    • 2017-12-02
    相关资源
    最近更新 更多