亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Tkinter 中重置下拉菜單的值和不顯示圖像?

如何在 Tkinter 中重置下拉菜單的值和不顯示圖像?

翻過高山走不出你 2022-06-14 17:47:02
目前我正在研究一個重置按鈕,它將所有內容設置回它的樣子。到目前為止,這就是它的樣子:def reset():   box1.deselect()   box2.deselect() #unticks all checkboxes   self.sendingBTN['state'] = 'disabled' #disables buttons back how I needed them to be現在我正在努力如何將下拉值設置回默認值。我的下拉菜單值包含特定文件夾內所有 jpg 文件的路徑。我已經為它分配了一個默認值:self.vars.set('All JPGs listed here..') # set the default option但是,當我從下拉菜單中選擇一個值時,默認值會消失,這就是我想知道如何重置它的原因。另外,我不太確定如何從顯示中刪除圖像。任何幫助將不勝感激!這是我的代碼:self.vars = StringVar()# Directoryself.directory = "C:/Users/spice/Desktop/allFiles/"self.choices = glob.glob(os.path.join(self.directory, "*.jpg"))self.vars.set('All JPGs listed here..') # set the default option# Imagesdef change_dropdown():    imgpath = self.vars.get()    img = Image.open(imgpath)    photo = ImageTk.PhotoImage(img)    label2.image = photo    label2.configure(image=photo)    self.CaptureScreen['state'] = 'normal'#return path valueself.p = Nonedef function2(value):    global p    self.p = Path(value)    print(self.p)#reset valuesdef reset():     self.Checkbox1.deselect()    self.Checkbox2.deselect()    self.Checkbox3.deselect()    self.Checkbox4.deselect()    self.Checkbox5.deselect()    self.Checkbox6.deselect()    self.Checkbox7.deselect()    self.Checkbox8.deselect()    self.Checkbox9.deselect()    self.Checkbox10.deselect()    self.Checkbox11.deselect()    self.Checkbox12.deselect()    self.CaptureScreen['state'] = 'disabled'    self.dataSend['state'] = 'disabled'#widgetsself.msg1 = Label(main, text = "All files here")self.msg1.grid(column = 0, row = 0)self.popupMenu = OptionMenu(main, self.vars, *choices, command = function2)self.popupMenu.grid(row=1, column=0)self.display_label = label2 = Label(main, image=None)self.display_label.grid(row=2, column=0, rowspan = 500)self.open_button = Button(main, text="Open", command=change_dropdown)self.open_button.grid(row=3, column=0)self.resetBtn = Button(main, text = "reset", command = reset)self.resetBtn.grid(column = 1, row = 2, sticky = W)這就是我試圖投入的def reset()        change_dropdown.delete(label2)
查看完整描述

2 回答

?
慕桂英3389331

TA貢獻2036條經驗 獲得超8個贊

要將下拉菜單重置為默認值,您可以嘗試以下代碼:

def reset(): 
    self.vars.set("All JPGs listed here..")


查看完整回答
反對 回復 2022-06-14
?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

我已經設法通過使用這個來刪除圖像:

config(image='')

接下來,我將嘗試清除下拉內容..


查看完整回答
反對 回復 2022-06-14
  • 2 回答
  • 0 關注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號