Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Ttk笔记本机架过多导致故障_Python_Tkinter_Ttk - Fatal编程技术网

Python Ttk笔记本机架过多导致故障

Python Ttk笔记本机架过多导致故障,python,tkinter,ttk,Python,Tkinter,Ttk,我正在Tkinter/Ttk中创建一个简单的SQLite数据库查看器。它由一个ttk笔记本组成,每个选项卡上都有一个表。对于较小的表,它可以正常加载,但对于包含1000多行的表,它会出现问题。 它的外观:它在大表上的外观:(顶部的白色部分覆盖在其他窗口上,这有点奇怪)有没有更好的方法来加载表以避免出现这种情况? 代码: 请回答您的问题,不要只说“it故障”。请创建一个不依赖您的数据库的数据库。我怀疑您的问题存在,无论数据是来自数据库还是来自循环。@BryanOakley我已经更改了代码,但这并

我正在Tkinter/Ttk中创建一个简单的SQLite数据库查看器。它由一个ttk笔记本组成,每个选项卡上都有一个表。对于较小的表,它可以正常加载,但对于包含1000多行的表,它会出现问题。
它的外观:

它在大表上的外观:

(顶部的白色部分覆盖在其他窗口上,这有点奇怪)
有没有更好的方法来加载表以避免出现这种情况?
代码:


请回答您的问题,不要只说“it故障”。请创建一个不依赖您的数据库的数据库。我怀疑您的问题存在,无论数据是来自数据库还是来自循环。@BryanOakley我已经更改了代码,但这并没有完全重现问题,尽管类似,我认为这可能是tkinter/tcl错误,因为我看不到任何东西(重要)错误,并且已经能够验证它是否适用于较小数量的行。python.exe中有1000行的应用程序崩溃。WIndows表明
tcl86t.dll
模块(版本8.6.2.9)中的异常代码8000003存在故障。@Henry:不幸的是,我认为情况就是这样。即使1000行看起来有点过多,一个正确编写的模块应该能够避免崩溃以及避免视觉上的“小故障”。您最好的选择可能是找到其他模块来满足您的需要(除了编写自己的模块)。我听说过一些叫做“tktables”、“tkinter表”或类似的东西。
import tkinter as tk
import tkinter.filedialog
from tkinter import ttk
import random

class dbTable(tk.Frame):
    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self, *args, **kwargs)
    def populateTable(self, data):
        for n1, line in enumerate(data):
            if n1 == 0: #Header
                bg = "lightgray"
            else:
                bg = "white"
            for n2, item in enumerate(line):
                f = tk.Frame(self, highlightthickness = 1, highlightbackground = "black", bg = bg)
                f.grid(row = n1, column = n2, sticky = "nesw")
                l = tk.Label(f, bg = bg, text = item)
                l.pack(padx = 3, pady = 3, fill = "both", expand = True)
        if len(data) == 1:
            f = tk.Label(self, text = "No data")
            f.grid(row = 2, column = 0, columnspan = len(data[0]))
class DatabaseViewer(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.title("Database viewer")
        self.loadData()
        self.openViewer()
    def loadData(self):
        self.tables = ["example"]
        self.tableHeaders = {"example":("header1","header2","header3","header4")}
        randData = [(n, random.randint(10,20000000), random.randint(10,20000000), random.randint(10,20000000), random.randint(10,20000000)) for n in range(1000)]
        self.tableData = {"example":randData}
    def openViewer(self):
        self.viewerFrm = tk.Frame(self)
        self.viewerFrm.pack()
        self.viewerNotebook = ttk.Notebook(self.viewerFrm)
        self.viewerNotebook.pack()
        for table in self.tables:
            f = tkinter.Frame(self.viewerNotebook)
            self.viewerNotebook.add(f, text = table)
            t = dbTable(f)
            t.pack(fill = "both", expand = True)
            t.populateTable([self.tableHeaders[table]] + self.tableData[table])

app = DatabaseViewer()
app.mainloop()