Python,Tkinter:NameError:未定义全局名称“Combobox”

时间:2014-03-28 14:43:41

标签: python tkinter ttk

我已经在Python中为我的gui应用程序创建了一个组合框但是在我的 init 函数中声明我的组合框时我遇到了这个错误:

TypeError: 'Combobox' object is not callable

以下是我正在使用的代码:

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错误或名称错误。

有谁知道这个问题的解决方案?

这是我可以在获得错误的同时制作代码的最小值:

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

1 个答案:

答案 0 :(得分:2)

尝试

textvariable = self.variableCombo_value