![](/img/trans.png)
[英](Mac OSX Catalina) Why can't I click a button in Tkinter and make it go blue?
[英]Can't click button on tkinter
我是 tkinter 的新手,我在使用 python GUI 上的按钮时遇到问题。 我创建了按钮和它后面的 function 但我无法单击按钮。 有人可以告诉我我做错了什么吗? 用户界面出现,我可以看到我无法点击的按钮。
import tkinter as tk
from tkinter import filedialog, Text
import os
#main
root = tk.Tk()
def addApp():
filename = filedialog.askopenfilename(initialir= "/", title= "Select File",
filetypes = (("executables", "*.exe"),
("all files", "*.*")))
canvas = tk.Canvas(root, height=700, width=700, bg="#33F9FF")
canvas.pack()
frame = tk.Frame(root, bg="white")
frame.place(relwidth=0.8, relheight=0.8, relx = 0.1, rely = 0.1)
openFile = tk.Button(root, text = "Open File", padx = 10, pady = 5, fg="black",
bg="#33F9FF", command="addApp")
openFile.pack()
runApps = tk.Button(root, text = "Run Apps", padx = 10, pady = 5, fg="black",
bg="#33F9FF")
runApps.pack()
root.mainloop()
非常,小错误。 您将命令参数添加为字符串而不是 function
openFile = tk.Button(root, text = "Open File", padx = 10, pady = 5, fg="black",
bg="#33F9FF", command=addApp)
编辑:openfiledialogbox 中的initialdir
参数有一个小错字
filename = filedialog.askopenfilename(initialdir= "/", title= "Select File",
filetypes = (("executables", "*.exe"),
("all files", "*.*")))
还有一个错误:
def addApp():
filename = filedialog.askopenfilename(initialdir= '/', title= "Select File",
filetypes = (("executables", "*.exe"),
("all files", "*.*")))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.