【发布时间】:2020-06-19 10:26:04
【问题描述】:
刚刚开始处理一些GUI。我是tkinter 的新手。
我可以使用.config 为各个标签设置label 的宽度和字体大小。
我想将此设置为特定列的默认值。
我试过了:
Label.config(width=70, font=('Courier',15))
但不断出错:
Traceback(最近一次调用最后一次): 文件“/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py”,第 3331 行,在 run_code 执行(code_obj,self.user_global_ns,self.user_ns) 文件“”,第 8 行,在 Label.config(width=70, font=('Courier',15)) 类型错误:configure() 缺少 1 个必需的位置参数:'self'
这样做的正确方法是什么?
完整代码:
from tkinter import *
from tkinter import ttk
reasons_window = Tk()
ttk.Style.configure('TLabel',width=70,font=('Courier',15))
reasons_window.geometry("500x200")
# Create rows for the reasons to be entered.
label1 = ttk.Label(reasons_window, text="Qty")
label1.grid(row=0,column=0)
# for field in fields
e1 = Entry(reasons_window)
e1.grid(row=0,column=1)
def eval_click():
if int(e1.get()) == 100:
print('GO AHEAD')
eval_button = Button(reasons_window, text="Evaluate", command=eval_click)
eval_button.grid(row=3, column=0)
reasons_window.mainloop()
【问题讨论】:
-
@stovfl 是的,它几乎回答了我能想到的所有问题。我猜不知道如何提出正确的问题。