Python,Tkinter:NameError:global name';组合框';没有定义

Python,Tkinter:NameError:global name';组合框';没有定义,python,tkinter,ttk,Python,Tkinter,Ttk,我已经用Python为我的gui应用程序创建了一个combobox,但是在我的init函数中声明我的combobox时出现了这个错误: TypeError:“Combobox”对象不可调用 以下是我使用的代码: class ProgramingPractice(Tk): def __init__(self): super(ProgramingPractice, self).__init__() self.variableCombo_value = Str

我已经用Python为我的gui应用程序创建了一个combobox,但是在我的init函数中声明我的combobox时出现了这个错误:

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()
我尝试了不同的解决方案,但我要么遇到了Attibute错误,要么遇到了name错误

有人知道这个问题的解决办法吗

这是我在仍然得到错误的情况下能够生成代码的最小值:

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()
试一试


什么是
ttk
,您是如何导入的?另外,Python2或3?ttk是tkinter主题的小部件集,从tkinter导入ttkYou不会在
\uuuu init\uuuu
中得到错误,而是在
问题变量的第二行中得到错误。尝试
self.variableCombo.configure(stuff)
。另外,
textvariable
参数可能应该是
StringVar
,而不是组合框本身…@tobias_k,使用
self.variableCombo.configure(stuff)
我知道得到错误
AttributeError:“function”对象没有属性“items”
我不确定“items”是什么。你在哪里做
self.variableCombo(…)
你试图将小部件用作可调用的-你可能想要
self.variableCombo.configure(width=self.formsize,textvariable…)
textvariable = self.variableCombo_value