2016-03-20 62 views
0

tkinterを使って作成したウィンドウに関数をどのように接続することができますか?私はそれらを接続するための数多くの方法を試したが、それは動作しません。データベースを新しいウィンドウに表示しようとしています。tkinterを使ってPythonで新しいウィンドウを開く問題

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() 

答えて

0

私が正しくあなたの質問を理解していれば、あなたはすでに、ウィンドウを持っていて、新しいものにデータを表示したいです。

その場合はTkinter's toplevel widgetを試してください。トップレベルにデータを追加するだけで、新しいウィンドウに表示されます

+0

これはどういう意味ですか?これはtop = Toplevel()を使用していて、引数として関数を渡していますか? – fumar97

+0

ウィジェットを他のウィジェットに追加する方法と同様に、トップレベルにウィジェットを追加することができます。たとえば、トップレベルに追加したいラベルがある場合は、 'mylabel = Label(top、text =" my text ")'を実行します。もちろん、ジオメトリマネージャを使用してウィンドウ内に適切に配置する必要があります。希望が役立ちます。 – VlassisFo

関連する問題