簡體   English   中英

Python,Tkinter:NameError:未定義全局名稱“Combobox”

[英]Python, Tkinter: NameError: global name 'Combobox' is not defined

我已經在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()

嘗試

textvariable = self.variableCombo_value

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM