簡體   English   中英

信息未填充 tkinter gui 中的表格行

[英]Information not filling the row of a table in a tkinter gui

我正在編寫一個程序,該程序將從網站上抓取數據並將數據放在 tkinter gui 的表中。

我找到了這個制作桌子的秘訣: https : //code.activestate.com/recipes/580793-tkinter-table-with-scrollbars/這非常適合我想要做的事情。

問題是我輸入的值沒有填充該行。 它們包裝得太早,使信息難以閱讀。 我該如何解決?

例子:

一張桌子的圖片

相關代碼:

from tkinter import *
import tabless # Name of the script linked above

root = Tk()
table = tabless.Table(root, ["Title 1", "Title 2", "Title 3", "Title 4"], column_minwidths=[200, 350, 100, 100])
table.pack(padx=10,pady=10,side=LEFT)
table.set_data([[1,2,3,4],[5,6,7,8], [9,10,11,12], [13,14,15,16], [17,18,19,20],[21,22,23,24], [25,26,27,28], [29,30,31,32], [33,34,35,36], [37,38,39,40], [41,42,43,44], [45,46,47,48], [49,50,51,52], [53,54,55,56], [57,58,59,60], [61,62,63,64], [65,66,67,68], [69,70,71,72], [73,74,75,76], [77,78,79,80], [81,82,83,84], [85,86,87,88], [89,90,91,92], [93,94,95,96], [97,98,99,100], [101,102,103,104], [105,106,107,108], [109,110,111,112], [113,114,115,116], [117,118,119,120], [121,122,123,124], [125,126,127,128], [129,130,131,132], [133,134,135,136], [137,138,139,140], [141,142,143,144], [145,146,147,148], [149,150,151,152], [153,154,155,156], [157,158,159,160], [161,162,163,164], [165,166,167,168], [169,170,171,172], [173,174,175,176], [177,178,179,180], [181,182,183,184], [185,186,187,188], [189,190,191,192], [193,194,195,196], [197,198,199,200]])
example_list = []
for i in range(0, 50):
    example_list.append(['thisisalongnumber12123123123', True, 'thisisashorternumber12123123123', 'thisisaname', 'thisisaverylongtitle12345678901111', 'number', 'number'])
for count, i in enumerate(example_list):
    table.cell(count, 0, i[3])
    table.cell(count, 1, i[4])
    table.cell(count, 2, i[5])
    table.cell(count, 3, i[6])

我將 tkinter.Message 換成了一個簡單的 tkinter.Label,“wraplength”參數為 300。這為我修復了它。

這是修改后的 DataCell 類

class Data_Cell(Cell):
    def __init__(self, master, variable, anchor=W, bordercolor=None, 
             borderwidth=1, padx=0, pady=0, 
             background=None, foreground=None, font=None):
    Cell.__init__(self, master, background=background,
                  highlightbackground=bordercolor, 
                  highlightcolor=bordercolor, 
                  highlightthickness=borderwidth, bd=0)

    self._message_widget = Label(self, textvariable=variable, 
                                 font=font, background=background,
                                 foreground=foreground,
                                 wraplength=300)
    self._message_widget.pack(expand=True, padx=padx, pady=pady,
                              anchor=anchor)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM