简体   繁体   中英

python tkinter Combobox doesn't populate windows hard drives

Dear Folks, My python Combobox doesn't populate the windows drives. Please Help!!!

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()

I tried to populate the combobox from the tuple and list. But the combobox remains blank.

I suppose you want to populate your ttk.Combobox vertically with your existing drives on the local PC, such as :

C:

D:

E:

To provide this, just need to convert dl to an ordinary string as

dl = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM