如何解决Tkinter - 组合框明文
我使用的是 Python 3.9。我正在尝试清除组合框中的选择。 当我尝试使用 .clear() 时,我收到一条错误消息, AttributeError: 'ComboBox' 对象没有属性 '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()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。