【问题标题】:i had problem with tkinter def not starting我遇到了 tkinter def 无法启动的问题
【发布时间】:2026-02-08 21:10:02
【问题描述】:

当我运行并按下开始按钮时我制作了 facebook 脚本我收到了这个错误我用 Tkinter 制作了这个 GUI 界面我正在使用 python 3 我的错误是当我点击开始按钮时他没有启动谷歌浏览器当我禁用 Tkinter 并通过命令行工作时,他可以正常工作,您可以看到错误屏幕截图:

import pyautogui as pg
import time
from selenium import webdriver
from getpass import getpass
from tkinter import *

window = Tk()
window.title('Facebook Sharing')
text = Label(window, text='Facebook Sharing Script', font="Source_Sans_Pro 20 bold")
text.pack()
frame = Frame(window)
frame.pack()

one = Frame(window)
one.pack( side = TOP )

frontframe = Frame(window)
frontframe.pack( side = TOP )


bottomframe = Frame(window)
bottomframe.pack( side = TOP )

lastframe = Frame(window)
lastframe.pack( side = TOP )

last = Frame(window)
last.pack( side = TOP )

Lable1 = Label(frame, text="Enter Your UserName!    ", font='Source_Sans_Pro 11')
Lable1.pack( side = LEFT)
user_name = Entry(frame, bd =5)
user_name.pack(side = RIGHT)

Lable2 = Label(frontframe, text="Enter Your Passowrd!     ", font='Source_Sans_Pro 11')
Lable2.pack( side = LEFT)
Password = Entry(frontframe, bd =5)
Password.pack(side = RIGHT)

Lable3 = Label(bottomframe, text="Enter Your Description!   ", font='Source_Sans_Pro 11')
Lable3.pack( side = LEFT)
description = Entry(bottomframe, bd =5)
description.pack(side = RIGHT)

Lable4 = Label(lastframe, text="Enter Your Keyword!       ", font='Source_Sans_Pro 11')
Lable4.pack( side = LEFT)
keyword = Entry(lastframe, bd =5)
keyword.pack(side = RIGHT)

Lable5 = Label(one, text="Enter Your Post Url!         ", font='Source_Sans_Pro 11')
Lable5.pack( side = LEFT)
post_url = Entry(one, bd =5)
post_url.pack(side = RIGHT)

Button_Start = Button(last, text="Start", fg="black", width=50, command=all)
Button_Start.pack( side = BOTTOM)


pg.FAILSAFE = True

#this is hidden def
def all():

print("Done")
window.mainloop()

错误!

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\User`enter code here`s\Hamza Lachi\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
TypeError: all() takes exactly one argument (0 given)

【问题讨论】:

    标签: python tkinter


    【解决方案1】:

    所以All() 是原生 Python 函数,你可以在下面的链接中阅读更多关于它的链接 all(iterable),这就是问题所在,Python 正在调用他的原生函数而不是你创建的函数。

    您可以通过更改函数名称来解决此问题。

    了解更多信息:

    【讨论】:

    • 正确!使用唯一且有意义的名称来命名您的函数和变量至关重要!
    • 文件 ".\All.py",第 55 行,在 中 Button_Start = Button(last, text="Start", fg="black", width=50, command=hi) NameError: name 'hi' 未定义
    • 不客气!您必须将函数 hi() 放在 Button_Start 之前。
    • 朋友!在创建模块和函数时要小心,名称很重要,不要创建与Python原生函数和模块同名的函数和模块,因为这样可能会产生冲突。