[英]Python, Tkinter: NameError: global name 'Combobox' is not defined
I have created a combobox for my gui application in Python but I have been getting this error when declaring my combobox in my init function: 我已经在Python中为我的gui应用程序创建了一个组合框但是在我的init函数中声明我的组合框时我遇到了这个错误:
TypeError: 'Combobox' object is not callable
Here is the code I am using for this: 这是我正在使用的代码:
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()
I have tried different solutions to this problem but I have either got an Attibute error or a name error. 我已经尝试了不同的解决方案来解决这个问题,但我遇到了Attibute错误或名称错误。
Does anyone know of a solution to this problem? 有谁知道这个问题的解决方案?
This is the smallest I can make the code while still getting the error: 这是我可以在仍然收到错误的同时制作代码的最小值:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.