2013-10-02 20 views
-1

我在這整個Python的東西很新,我的問題是如何使一個按鈕運行命令,點擊它時,而不是之前。
我在網上搜索了很多,但我沒有找到任何東西。 我完全不理解這些類。有沒有其他方法可以做到這一點?爲什麼直接打開「命令」而不是點擊按鈕時? Python 3

這是我的工作,我在程序上做了。 感謝您的幫助

from tkinter import * 
import os 
t = "" 

def ordner(x): 
    print ("def") 
    if os.path.exists(os.path.join("/Kunden/",x)) == True: 
     pass 
    else: 
     os.mkdir(os.path.join("/Kunden/",x)) 

def E1holen(): 
    x = E1.get() 
    ordner(x) 


#Hauptfenster 
main=Tk(className='Kundendatenbank') 
main.iconbitmap('icon.ico') 
#Inhalt Hauptfenster 
L1 = Label(main, text="Kundenname:") 
L1.pack(side = LEFT) 
E1 = Entry(main, bd =5, textvariable=t) 
E1.pack(side = RIGHT) 
a = Button (main, text=("erstellen/bearbeiten"), command=E1holen()).pack() 

main.mainloop() 

回答

1

它會立即運行,因爲您告訴它。

什麼是調用Python中的函數的語法?這是foo(),對吧?所以,當你做command=E1holen()時,python應該做什麼?它應該調用E1holen(),然後將結果傳遞給command屬性。

換句話說,在command屬性需要參考的功能,但調用功能,並給予command屬性不管這函數返回因爲()的。解決方案?刪除()

a = Button(..., command=E1holen) 
相關問題