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

标签 python tkinter

亲爱的人们, 我的 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/

相关文章:

python - 如何退出pyplot循环?

python - 如何在 tkinter 中显示加载消息

一些unicode字符的Python编码错误

python - 是否有相当于 Octave 命令 `format bit` 的 python?

python - Mypy 类型的连接元组

python-3.x - 需要从不同的类调用类方法而不初始化第一个类或其他方式

每 30 秒或特定时间间隔后的 Python Tkinter 调用事件

python - 如何使用pygame依次运行声音循环?

python - 在 Python 中给一个类起别名

python - 在python中将某些内容从一个文件写入另一个文件