gpt4 book ai didi

python - 我的 tkinter 按钮命令功能有问题

转载 作者:行者123 更新时间:2023-12-01 00:38:33 26 4
gpt4 key购买 nike

当我运行时,我制作了 Facebook 脚本,他给了我错误 hi is not Defined当我禁用 Tkinter 并使用 power shell 启动时,他没有启动,他工作正常,请帮助我!我正在使用 python 3 这是我的错误屏幕截图 我在运行时使用 Tkinter 创建了这个 GUI 他给了我一个错误并且没有启动

enter image description here

Python 代码

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=hi)
Button_Start.pack( side = BOTTOM)


pg.FAILSAFE = True


def hi():
driver = webdriver.Chrome()
pg.click(1029, 109, duration=.30)
driver.get('https://www.facebook.com/')
driver.maximize_window()
time.sleep(1)

print("Done")
window.mainloop()

错误

Traceback (most recent call last):
  File ".\All.py", line 55, in <module>
    Button_Start = Button(last, text="Start", fg="black", width=50, command=hi)
NameError: name 'hi' is not defined

最佳答案

您在将 hi 函数分配给按钮后定义它。在创建按钮之前放置 hi 函数。

做这样的事情:

def hi():
...
...

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

关于python - 我的 tkinter 按钮命令功能有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57550597/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com