我是 Python 的新手,并且在学习的过程中仍在学习。我需要逐行读取 SQL 语句数据库并自动刷新表视图。
这是我加载数据的 oracle 文件 (Data_File)
import cx_Oracle
def getConnection():
connection = cx_Oracle.connect("****@localhost:1521/orcl")
return connection
connection = getConnection()
cursor = connection.cursor()
sql_fetch_data = "SELECT a, b, c from table"
rowdata = cursor.execute(sql_fetch_data)
coldata = [i[0] for i in rowdata.description]
rowdata = [list(r) for r in rowdata]
connection.commit()
cursor.close()
这是我的主要代码:
import ttkbootstrap as ttk
import sys
import os
from Data_File import rowdata, coldata
from ttkbootstrap.tableview import Tableview
from ttkbootstrap.constants import *
app = ttk.Window(themename="superhero", size=(1000, 500))
app.geometry("1020x500")
app.title("USER MANAGEMENT")
app.resizable(True, True)
app.place_window_center()
label = ttk.Label(app, text="USER MANAGEMENT VERSION 1.0", bootstyle=DEFAULT)
label.pack(pady=5)
label.config(font=("Arial", 20, "bold"))
button_frame = ttk.Frame(app)
button_frame.pack(side=TOP, fill=BOTH, expand=TRUE, padx=3, pady=3)
ttk.Button(button_frame, text="Refresh", bootstyle="OUTLINE-SUCCESS",).\
pack(side=TOP, fill=BOTH, expand=TRUE, padx=3, pady=3)
def place_window_center(self):
"""Position the toplevel in the center of the screen. Does not
account for titlebar height."""
self.update_idletasks()
w_height = self.winfo_height()
w_width = self.winfo_width()
s_height = self.winfo_screenheight()
s_width = self.winfo_screenwidth()
xpos = (s_width - w_width) // 2
ypos = (s_height - w_height) // 2
self.geometry(f'+{xpos}+{ypos}')
dt = Tableview(
master=app, # The parent widget
paginated=False,
searchable=True,
height=50,
autoalign=True,
autofit=True,
pagesize=30,
coldata=coldata,
rowdata=rowdata,
bootstyle=DANGER,
)
dt.pack(side=TOP, fill='y', expand=TRUE, padx=10, pady=10)
app.mainloop()
我假设这是一个简单的问题,但我已经尝试了很长时间。我什么都没想到。