Button 为什么";“命令”;直接打开而不是单击按钮时打开?Python 3
我对Python这整件事还很陌生,我的问题是如何使一个按钮在单击它时而不是之前运行命令。Button 为什么";“命令”;直接打开而不是单击按钮时打开?Python 3,button,tkinter,command,Button,Tkinter,Command,我对Python这整件事还很陌生,我的问题是如何使一个按钮在单击它时而不是之前运行命令。 我在网上搜索了很多,但什么也没找到。 我一点也不懂这些课。没有别的办法吗 这是我的工作,我做的节目。 谢谢你的帮助 from tkinter import * import os t = "" def ordner(x): print ("def") if os.path.exists(os.path.join("/Kunden/",x)) == True: pass
我在网上搜索了很多,但什么也没找到。 我一点也不懂这些课。没有别的办法吗 这是我的工作,我做的节目。 谢谢你的帮助
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()
它会立即运行,因为你告诉它 Python中调用函数的语法是什么?这是
foo()
,对吗?那么,当您执行command=E1holen()
时,python应该做什么?它应该调用E1holen()
,然后将结果传递给命令
属性
换句话说,命令
属性引用一个函数,但是因为()
你调用了这个函数,并给出了命令
属性,不管这个函数返回什么。解决方案是什么?删除()
:
a = Button(..., command=E1holen)