我正在使用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()
在这里的任何解释将不胜感激。
答案 0 :(得分:0)
我找到了解决方案;
raw_root.update()
raw_root.deiconify()
在文件对话框之前放入根并退出,然后在生成列表框之前放入上面的代码,即可解决此问题。