我对 tkinter 按钮命令功能有疑问
I had problem with tkinter button command function
当我 运行 他给我错误 hi is not defined 时,我制作了 Facebook 脚本
当我禁用 Tkinter 并使用电源启动时他没有启动 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)
当我 运行 他给我错误 hi is not defined 时,我制作了 Facebook 脚本 当我禁用 Tkinter 并使用电源启动时他没有启动 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)