Я пытаюсь получить имя персонажа с помощью поля ввода в tkinter.
def create2():
global created
label.config(text ='You need to have a name.')
entry = tk.Entry(storywindow, text = 'Enter your name...')
entry.place(relx = .01, rely = .89, relheight = .1, relwidth = .69)
hero.name = entry.get
Как связать пользовательский ввод с переменной? Спасибо
Обновление с моим рабочим кодом:
def stats():
label.config(text = hero.name + '\n'+ hero.mclass+'\nLevel: ' + str(hero.level) )
label.config(text = 'Hitpoints: '+ str(hero.hp) +'/'+str(hero.max_hp))
def create2():
label.config(text ='You need to have a name.')
txt = tk.Entry(storywindow)
txt.place(relx = .01, rely = .89, relheight = .1, relwidth = .69)
def getname():
name = txt.get()
hero.name = name
txt.destroy()
submit.destroy()
stats()
submit = tk.Button(storywindow, text= 'Submit', command = getname)
submit.place(relx = .7, rely = .89, relheight = .1, relwidth = .29)
def create():
label.config(text ='Please choose a main class.')
war = tk.Button(storywindow, text = 'Warrior', command = lambda:[warrior(),war.destroy(),mag.destroy(),rog.destroy(),pri.destroy()])
war.place(relx = .01, rely = .94, relheight = .05, relwidth = .24)
mag = tk.Button(storywindow, text = 'Mage', command = lambda:[mage(),war.destroy(),mag.destroy(),rog.destroy(),pri.destroy()])
mag.place(relx = .26, rely = .94, relheight = .05, relwidth = .24)
rog = tk.Button(storywindow, text = 'Rogue', command = lambda:[rogue(),war.destroy(),mag.destroy(),rog.destroy(),pri.destroy()])
rog.place(relx = .51, rely = .94, relheight = .05, relwidth = .24)
pri = tk.Button(storywindow, text = 'Priest', command = lambda:[priest(),war.destroy(),mag.destroy(),rog.destroy(),pri.destroy()])
pri.place(relx = .76, rely = .94, relheight = .05, relwidth = .23)