2014-03-28 60 views
2

我创建了一个组合框在Python我的GUI应用程序,但在宣布我的组合框当我初始化功能我已经收到此错误:的Python,Tkinter的:NameError:全局名称“组合框”没有定义

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

到底是什么'ttk',你怎么导入呢?另外,Python 2或3? –

+0

ttk是tkinter的主题部件集,从tkinter导入ttk – Tumbler

+0

你不会在'__init__'中得到错误,但是在'questionVariables'的第二行。试试'self.variableCombo.configure(stuff)'。另外,'textvariable'参数可能应该是'StringVar',而不是组合框本身... –

回答

2

尝试

textvariable = self.variableCombo_value 
相关问题