使用tkinter在python中发布打开新窗口

时间:2016-03-20 18:40:12

标签: python 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()

1 个答案:

答案 0 :(得分:0)

如果我正确理解了您的问题,您已经有了一个窗口,并且您希望以新的方式显示您的数据。

在这种情况下,您应该尝试Tkinter's toplevel widget。只需在顶层添加数据,它就会显示在一个新窗口中

相关问题