[英](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.