问题描述
我有一个庞大的列表l1
,其中包含近1074个应用程序名称
I have a huge list l1
of almost 1074 app names in it
['10 Best Foods for You' '104 找工作 - 找工作 找打工 找兼職 履歷健檢 履歷診療室' '11st' ...
'Hotwire Hotel & Car Rental App' 'Housing-Real Estate & Property'
'Houzz Interior Design Ideas']
我想在以下相同的窗口中显示所有应用程序,但是所有这些应用程序都不可见.
I want to display all the apps in the same window as below, but all of them aren't visible.
控制台中出现以下错误:
Im getting the following error in the console:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/Samit Patil/Desktop/PlaystoreStudy Project/test_gui.py", line 496, in <lambda>
tk.Button(frame, text='Select query', width='15', font=("Open Sans", 13, 'bold'), bg='brown', fg='white',command=lambda c=i:query(c+1)).grid(row=i,column=1,sticky=W)
File "C:/Users/Samit Patil/Desktop/PlaystoreStudy Project/test_gui.py", line 439, in query
populate(frame)
File "C:/Users/Samit Patil/Desktop/PlaystoreStudy Project/test_gui.py", line 418, in populate
tk.Label(frame, text=l1[5], width='80',anchor=W,relief=GROOVE, height="4", font=("Calibri", 10, 'bold'), fg='black', bg='Green',wraplength=500).grid(row=i,column=0,sticky=W)
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 2766, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 2299, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: character U+1f602 is above the range (U+0000-U+FFFF) allowed by Tcl
我的代码:
qy14apps = Toplevel(screen2)
qy14apps.title("Select one app")
adjustWindow(qy14apps) # configuring the window
l1=list_apps()
print (len(l1))
def onFrameConfigure(canvas):
canvas.configure(scrollregion=canvas.bbox("all"))
def populate(frame):
for i in range(len(l1)):
tk.Label(frame, text=l1[i], width='80',anchor=W,relief=GROOVE, height="4", font=("Calibri", 10, 'bold'), fg='black', bg='Green',wraplength=500).grid(row=i,column=0,sticky=W)
#l2=Label(text="\n", bg='white')
#l2.grid(row=i+1,column=0)
tk.Button(frame, text='Select app', width='15', font=("Open Sans", 13, 'bold'), bg='brown', fg='white',command="").grid(row=i,column=1,sticky=W)
canvas = tk.Canvas(qy14apps, borderwidth=0, background="#ffffff")
frame = tk.Frame(canvas, background="#ffffff")
vsb = tk.Scrollbar(qy14apps, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=vsb.set)
vsb.pack(side="right", fill="y")
canvas.pack(side="left", fill="both", expand=True)
canvas.create_window((4,4), window=frame, anchor="nw")
frame.bind("<Configure>", lambda event, canvas=canvas: onFrameConfigure(canvas))
populate(frame)
我不知道即时通讯出了什么问题,是因为列表太大了吗?我将相同的概念应用于20个元素的列表,然后它起作用了.任何帮助将是非常可贵的.谢谢.
I dont understand where im going wrong, is it because the list is too huge?I have applied the same concept for a list of 20 elements and it worked then.Any help would be highly appreciable. Thanks.
推荐答案
我宁愿将这么多的数据插入到列表框中,然后将按钮链接到一个通过列表框变量检索所选列表项的函数
I would rather insert that amount of data into a listbox and link the button to a function that retrieves the selected list item via your listbox variable
listboxvariablename.curselection()
要删除花括号,您可能会在每个列表框条目周围出现问题,请在将列表插入列表框之前先遍历列表,然后按索引对其进行引用.将条目插入列表框时,这将去除花括号.
To remove the curly braces you might get around each listbox entry, loop over the list before inserting it into the listbox and refer to the entry by it's index. That will strip out the curly braces while inserting the entries into the listbox.
这篇关于Tkinter长列表显示在网格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!