0

我正在使用 Python 3.9。我正在尝试清除组合框中的选择。当我尝试使用 .clear() 时,我收到一条错误消息 AttributeError: 'Combobox' object has no attribute 'clear'。任何人都可以帮助我纠正程序中的错误吗?

import tkinter as tk
from tkinter import ttk
import self as self


class window1:

    def __init__(self, master):
        self.master = master
        self.frame1 = tk.Frame(self.master, width=450, height=75)
        self.frame1.place( x=5, y=5 )
        self.months = ('Jan', 'Feb', 'Mar')

    def combo_box(self):
        self.cbox = ttk.Combobox(self.frame1, state="readonly", width=30)
        self.cbox['values'] = self.months
        self.cbox.place(x=10, y=20)

    def clear(self):
        self.cbox.clear()

    def Clear_button(self):
         Button = tk.Button(self.frame1, text="clear", width=20,command=self.clear)
         Button.place(x=250,y=18)

def main():
    root = tk.Tk()
    root.geometry( "450x75" )
    app = window1( root )
    app.combo_box()
    app.Clear_button()
    root.mainloop()

if __name__ == '__main__':
    main()
4

0 回答 0