Tkinter - Combo box clear text

394 Views Asked by At

I am using Python 3.9. And I am trying to clear the selection from the combo box. When I tried with .clear(), I am getting an error message, AttributeError: 'Combobox' object has no attribute 'clear'. Can anybody help me to correct the error on my program?

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

There are 0 best solutions below