我試圖用tkinter列出我從資料庫中得到的所有資料。 我在關注這個帖子。https://www.geeksforgeeks.org/create-table-using-tkinter/
我得到了這個錯誤:
我得到了這個錯誤。
檔案"/Users/nobu/WorkSpace/Python/CommandLineApps/guineapig/guineapig/gui_tkinter。 py", line 18, in __init__
self.entry.insert(END, result[i][j])
檔案 "/usr/local/Cellar/[email protected]/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", 行 3056, in insert
self.tk.call(self._w, 'insert', index, string)
_tkinter.TclError: wrong # args: should be ".!entry4 insert index text".
這里是我的代碼:
from tkinter import *
import mysql.connector
import utils
class Table。
def __init__(self,root, result)。
# code for creating table.
total_rows = len(result)
total_columns = len(result[0] )
for i in range(total_rows)。
for j in range(total_columns)。
self.e = Entry(root, width=20, fg='white')
self.e.grid(row=i, column=j)
self.e.insert(END, result[i][j]) # <- 這里我得到一個錯誤。
def get_all()。
connection, cursor = utils.connect_db()
with connection:
root = Tk()
cursor.execute("SELECT * FROM item ORDER BY item_id DESC"/span>)
結果 = cursor.fetchall()
if len(result) == 0:
label = Label(text="沒有專案。請創建一個。")
else:
table = Table(root, result)
root.mainloop()
我對tkinter非常陌生。請幫助我解決這個問題。
uj5u.com熱心網友回復:
謝謝你 @Bryan Oakley!
我的串列中有None,所以我這樣做:
if result[i][j] is not None:
self.entry.insert(END, result[i][j])
else:
self.entry.insert(END, "無")
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/319454.html
標籤:
