如何创建一个按钮以打开一个打印所有记录的新窗口。 在程序的以下部分中,我无法在新窗口中打印记录,但它会在已创建的窗口中打印&;新窗口仍然是空的。 以下是该计划的一小部分:-
root = Tk()
def query():
query = Tk()
query.title('Records')
query.iconbitmap(r'C:\Users\pankaj\Downloads\Elegantthemes-Beautiful-Flat-Document.ico')
query.geometry("450x350")
#Create a database or connect to one
conn = sqlite3.connect('Payslip.db')
# Create cursor
c = conn.cursor()
#Query the database
c.execute("SELECT *,oid from Payslip")
records = c.fetchall()
#print(records)# to print in the background
#Loop the results
print_records = ''
for record in records: #to show the records
print_records += str(record[0]) +"\t" + str(record[8])+ "\n"# \t to give space(tab) between them
query_label = Label(root, text=print_records)
query_label.grid(row=14, column=0, columnspan=2)
#Commit Change
conn.commit()
# Close Connection
conn.close()
#create a Query button
query_btn = Button(root, text="Show Records", command=query)
query_btn.grid(row=9,column=0, columnspan=2, pady=10, padx=10, ipadx=135)
您正在尝试打印查询标签中的打印记录,您将其分配给根窗口:
query\u label=label(root,text=print\u记录)
您说您创建了一个新窗口,但我在代码中看不到它,因此您可能希望执行以下操作:
无论您想做什么:
查询标签=标签(新建窗口,文本=打印记录)
相关问题 更多 >
编程相关推荐