【发布时间】:2021-12-15 12:48:52
【问题描述】:
大家好!我有一个问题,我希望你能帮助我。 我正在做有问题的窗口,我想从条目中获取文本。 当我得到它时(我正在使用'EntryValue = EntryName.get()')它没有给出错误,但是当我想用它打印它时 PyAutoGUI.typewrite(EntryValue) 它没有打印出来,因为没有任何值 在我的变量中。
这是我的代码:
**from tkinter import *
import pyautogui as pg
import time
EntryThatAnswersToQuestionValue = ""
def FunctionThatCreatesWindowThatFindsProgramm():
WindowThatFindsProgram = Toplevel(Root)
WindowThatFindsProgram.iconbitmap(r'C:\Users\Murad\Desktop\My Factory\Programmes\J.A.R.V.I.S\Icon\QuestionIcon.ico')
WindowThatFindsProgram.title("J.A.R.V.I.S. Has a question.")
WindowThatFindsProgram.geometry('350x250')
LabelThatExplainsWhatToDoInWindowThatFindsProgram = Label(WindowThatFindsProgram,text="Please, write your programm's name sir."
,fg='black',font='Arial 10 bold')
LabelThatExplainsWhatToDoInWindowThatFindsProgram.pack()
EntryThatAnswersToQuestion = Entry(WindowThatFindsProgram)
EntryThatAnswersToQuestion.pack()
EntryThatAnswersToQuestionValue = EntryThatAnswersToQuestion.get()
OKButton = Button(WindowThatFindsProgram,text=" OK ",fg='black',font='Arial 10 bold',command=FunctionThatFindsProgramm)
OKButton.pack()
def FunctionThatFindsProgramm():
pg.hotkey('winleft')
time.sleep(1)
pg.typewrite(EntryThatAnswersToQuestionValue,3)
time.sleep(1)
pg.hotkey('enter')**
Root = Tk()
Root.iconbitmap(r'C:\Users\Murad\Desktop\My Factory\Programmes\J.A.R.V.I.S\Icon\Icon.ico')
Root.title("J.A.R.V.I.S.")
Root.geometry('960x540')
Root['bg'] = 'black'
MainMenu = Frame(Root,bg='black')
MainMenu.pack()
JarvisTextGreeting = Label(MainMenu,text="Hello, sir. You can tell the below commands for execution.",bg='black'
,fg='blue',font='Arial 15 bold')
JarvisTextGreeting.pack()
ButtonFindingTheProgramm = Button(MainMenu,text="J.A.R.V.I.S. Please find programm that I will tell you on my PC"
,bg='blue',fg='black',font='Arial 10 bold',command=FunctionThatCreatesWindowThatFindsProgramm)
ButtonFindingTheProgramm.pack()
Root.mainloop()
【问题讨论】:
-
您在创建条目后立即调用了
.get()。当然变量是空的——用户什么时候有机会输入任何东西?
标签: python tkinter pyautogui tkinter-entry