我已经在 Python 中为我的 gui 应用程序创建了一个组合框,但是在我的 init 函数中声明我的组合框时出现了这个错误:
TypeError: 'Combobox' 对象不可调用
这是我为此使用的代码:
class ProgramingPractice(Tk):
def __init__(self):
super(ProgramingPractice, self).__init__()
self.variableCombo_value = StringVar()
self.variableCombo = ttk.Combobox()
def questionVariables(self):
self.variableCombo_value = StringVar()
self.variableCombo(self.formSize, textvariable = self.variableCombo, state = 'readonly')
self.variableCombo['values'] = ('Month', 'Year', 'Age', 'Day')
self.variableCombo.pack()
我已经尝试了不同的解决方案来解决这个问题,但我遇到了属性错误或名称错误。
有谁知道这个问题的解决方案吗?
这是我在仍然收到错误的情况下可以编写的最小代码:
import sys
from tkinter import *
from tkinter import ttk
class ProgramingPractice(Tk):
def __init__(self):
super(ProgramingPractice, self).__init__()
self.formSize()
self.variableCombo_value = StringVar()
self.variableCombo = ttk.Combobox()
def formSize(self):
self.geometry("700x450+200+200") # Sets the size of the gui
def questionVariables(self):
self.variableCombo_value = StringVar()
self.variableCombo.configure(self.formSize, textvariable = self.variableCombo_value, state = 'readonly')
self.variableCombo['values'] = ('Month', 'Year', 'Age', 'Day')
self.variableCombo.pack()
pp = ProgramingPractice()
pp.questionVariables()
最佳答案
尝试
textvariable = self.variableCombo_value
关于 python ,Tkinter : NameError: global name 'Combobox' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22715974/