我想向tkinter中的标签小部件添加两个文本变量和文本

2024-04-23 17:19:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个tkinterLabel小部件,用于在新窗口中显示查询结果。我想根据查询选择在同一标签中显示两个内容

这是我的密码:

Label(newWindow, textvariable=selected_diff + " Hikes in " + selected_park, width=50, 
      fg="black", font=("bold", 12), bd=1, relief="raised").grid(row=0, column=3)

我知道我可以只创建3个独立的Label,但我认为这看起来很糟糕,而且很粗糙

这是我的回调错误-我猜您不能使用+在同一个小部件中连接strStringVar?似乎不太可能-更有可能是我做了一些格式错误

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\mount\anaconda3\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "F:/PycharmProjects/SIE557_2021_FP/fp_comboboxes.py", line 289, in search_hikes
    Label(newWindow, textvariable=selected_diff + " Hikes in " + selected_park, width=50, fg="black", font=("bold", 12), bd=1, relief="raised").grid(row=0, column=3)
TypeError: unsupported operand type(s) for +: 'StringVar' and 'str'

Process finished with exit code 0

Tags: inpark部件diffwidthlabelbdblack