我正在使用Pmw创建一个不错的列表框。首先,我通过Tkinter文件对话框获得一个文件路径,然后对该位置的数据进行一些操作。然后我试着显示列表框。
如果我在文件对话框行之前放置根并撤回,则列表框将不会出现。但是,如果我把它移到文件对话框请求之后,列表框就会出现,但我找不到摆脱根窗口的方法。
import pandas as pd
import pyautogui as gui
import tkinter as tk
from tkinter import filedialog
from tkinter import *
from pathlib import Path
import Pmw
all_file_path = filedialog.askdirectory()
raw_root = tk.Tk()
raw_root.withdraw()
---------------------
# Do some stuff
---------------------
class choiceBox( Frame ):
def __init__( self, listItems ):
Frame.__init__( self )
self.pack( expand = YES, fill = BOTH )
self.master.title( "Select" )
self.listBox = Pmw.ScrolledListBox( self,
items = listItems,
listbox_height = 5,
vscrollmode = "static",
listbox_selectmode = EXTENDED )
self.listBox.pack( side = LEFT, expand = YES, fill = BOTH,padx = 5, pady = 5 )
self.copyButton = Button( self,text = ">>>", command = self.addThing )
self.copyButton.pack( side = LEFT, padx = 5, pady = 5 )
self.chosen = Pmw.ScrolledText( self,text_height = 6,text_width = 20 )
self.chosen.pack( side = LEFT, expand = YES, fill = BOTH,padx = 5, pady = 5 )
def addThing( self ):
self.chosen.clear()
selected = self.listBox.getcurselection()
if selected:
for item in selected:
self.chosen.insert( END, item + "n" )
names = ("A", "B", "C", "D")
choiceBox( names ).mainloop()
这里的任何解释都将不胜感激。
我找到了解决方案;
raw_root.update()
raw_root.deiconify()
将root和draw放在filedialog之前,然后将上面的代码放在生成列表框之前,修复了这个问题。