提问者:小点点

将多个列表放置在另一个列表中并显示在tkinter的列表框中? 尝试了,但在一些文本中得到了花括号


我试图使这个计算器为我的工作涉及费用的项目与不同的类别,但列表框是哪里我卡住了。 我正在尝试使用list_all变量显示列表框中的所有项目,同时仍然对为每个单独列表选择的项目应用不同的费用变量。 名单是这样出来的。 但我试着把每一个项目放在一个单行上,以及去掉一些项目周围的括号,我试着找到一个解决办法,但我什么也找不到。

from tkinter import *
import tkinter as tk
from tkinter import messagebox
from tkinter import filedialog
from tkinter import ttk
from PIL import ImageTk, Image
import pymysql
import os
import shutil

principal = 0

interest = .015

bracket = 0

car_list = ["Car"]

list_0 = ["Jewelry"]

list_4 = ["CDs", "Movies", "Watches", "Video Games"]

list_6 = ["Camera", "Carpet tools", "Cell phones & Accesories", "Cement Hand Tools", "Coins & Money", "Clothing & Fashion", "Gift Cards",
"GPS", "Hand tools", "Harmonica", "Headphones", "Hunting", "MP3/iPod", "Machinist tools", "Meters/Testers", "Misc Auto Tools", "Nailers/Staplers",
"Office Equipment", "Paint", "Planers/Joiners", "Pool (billiards)", "Portable Audio/Video", "Sanders/Grinders", "Shoes", "Skates", "Rotozip",
"Shop Supplies" "Team Sports", "Tennis", "Toys", "Water Sports", "Winter Sports"]

list_10 = ["One of a kind", "Air Tools ", "Archery", "Art", "Band Saws", ]

list_15 = ["Televisions"]

list_25 = []

list_all = (list_4, list_6, list_10, list_15, list_25)


form = tk.Tk()
form.title("Fee Calculator")
form.geometry("500x280")

tab_parent = ttk.Notebook(form)


tab1 = ttk.Frame(tab_parent)
tab2 = ttk.Frame(tab_parent)
tab3 = ttk.Frame(tab_parent)

tab_parent.add(tab1, text="General Merch")
tab_parent.add(tab2, text="Jewelry")
tab_parent.add(tab3, text="Cars")

tab_parent.pack(expand=1, fill='both', side= 'top')


#for loop to increase width of list box
len_max = 0

for m in list_all:
    if len(m) > len_max:
        len_max = len(m)


# === WIDGETS FOR TAB ONE
listbox = Listbox(tab1, width = len_max)  

listbox.insert('end', *list_all)

listbox.pack()

#listbox categories
lbl = Label(tab1,text = "Categories") 
lbl.place(x=385,y=0) 
listbox.place(x=355, y=25)

共1个答案

匿名用户

只要改变:

listbox.insert('end', *list_all)

致:

for i in list_all:
    listbox.insert('end', *i)

list_all是2D列表而不是字符串