gpt4 book ai didi

python tkinter Combobox 不填充 Windows 硬盘驱动器

转载 作者:太空宇宙 更新时间:2023-11-03 21:00:41 24 4
gpt4 key购买 nike

亲爱的人们,我的 python Combobox 不填充 Windows 驱动器。请帮忙!!!

import tkinter as tk
from tkinter import ttk
from tkinter import font
import os.path

win = tk.Tk()
win.title("AR Duplicate File Search")
win.geometry("600x600")
win.configure(bg = 'green')


#----------------------------------Combo Box-----------------------------
dl = ['ABCDEFGHIJKLMNOPQRSTUVWXYZ']
drives = ['%s:' % d for d in dl if os.path.exists('%s:' % d)]
def convert(list):
return tuple(list)
listdrive = convert(drives)

search_loc_var = tk.StringVar()
search_loc_cmbbx1 = ttk.Combobox(win, width = 22, textvariable =
search_loc_var, state = 'readonly', values = drives)

# Defining the state readonly will restrict the user from typing anything
# in the combobox.
search_loc_cmbbx1['values'] = listdrive
search_loc_cmbbx1.grid(row = 2, column = 1)

win.mainloop()

我尝试从元组和列表中填充组合框。但组合框仍为空白。

最佳答案

我想您想用本地 PC 上的现有驱动器垂直填充 ttk.Combobox,例如:

C:

D:

E:

要提供此功能,只需将 dl 转换为普通字符串

dl = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

关于python tkinter Combobox 不填充 Windows 硬盘驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55720358/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com