簡體   English   中英

使用tkinter從sqlite3數據庫輸出文本

[英]Using tkinter to output text from sqlite3 database

我已經建立了一個數據庫並添加了一些隨機細節。 我已經從數據庫中提取了這些數據,並且需要在Tkinter GUI窗口中將其輸出。 當使用Label輸出內容時,通常會放置文本。

example = Label(self.frame, text='Example')

還有其他我應該使用的東西而不是標簽嗎?

def create_records():
    c.execute('CREATE TABLE IF NOT EXISTS MemberRecordsTable(surname TEXT, 
    firstname TEXT, membertype TEXT, datejoined TEXT)')

def readrecords(self):
    c.execute('SELECT * FROM MemberRecordsTable') 
    for row in c.fetchall():
        memberprint2 = Label(self.frame, text = row)
def memberprint(self):
    self.clearframe()
    readrecords()

您為每一行創建一個新標簽。 如果要將所有數據放在一個容器http://effbot.org/tkinterbook/text.htm中,請使用“文本”小部件。 請注意,create_records()缺少一個self,因此它不像其他2個函數那樣屬於類的一部分,

text_w = Text(self.frame, height=20, width=10, wrap="none")
text_w.grid(row=0, column=0)

......

text_w.insert(END, any_string)

暫無
暫無

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

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