繁体   English   中英

使用Tkinter在python中打开新窗口的问题

[英]Issue opening new window in python with tkinter

我想知道如何将函数连接到使用tkinter创建的窗口。 我尝试了多种方法将它们连接起来,但无法正常工作。 我正在尝试在新窗口中显示数据库。

import sys  # Import the sys 
from Tkinter import * # Makign a Window from the library
import Tkinter as tk
import sqlite3 as sql # Connection 
con = sql.connect('ALL') # Connection to database and name 
cur = con.cursor() # Connection to database

def onclick(obj):

  data = obj.data_customer()
  for row in data:
    print(row)

  root = tk.Tk()
  root.title("Customer Data")
  root.geometry("200x100+30+30")
  root.configure(bg="white")
  button = tk.Button(onclick, text="Lift", command=onclick(obj))
  button.pack

  #root = Tk()   #create the root window
  #root.data
  #root.title("Data") #modify the window
  #root.geometry("800x800")
  #root.mainloop()  #Start the window's event-loop

  #root = Tk()
  #text.insert(INSERT, "")
  #text.insert(END, self.data_customer)
  #text.pack()
  #root.title("CustomerData") #changes title name
  #onclick(data)
  #root.mainloop()

如果我正确理解了您的问题,您已经有一个窗口,并且想要在一个新窗口中显示数据。

在这种情况下,您应该尝试使用Tkinter的顶层小部件 只需在顶层添加您的数据,它将显示在新窗口中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM