对于一个游戏,我被编写了将字符串转换为某些命令的代码(看一下代码,它工作正常),但是我实际上是在编写一个tkinter程序!需要有关该代码的帮助
-我试图将该命令放在Button上,并将textvariable结果放置在premier2中
import textwrap
def generate_lore(sample_text):
wrapper = textwrap.TextWrapper(width=40)
dedented_text = textwrap.dedent(text=sample_text)
original = wrapper.fill(text=dedented_text)
t = original.split("\n")
result = ""
for str in t:
result += "/lore add " + str + "\n"
print(result)
from lore_hb_fenetre import generate_lore
# Creation fenetre
window = Tk()
color="#538E6D"
window.title("Orym")
window.geometry("720x480")
window.config(background='#538E6D')
# Creation frame avec text
frame = Frame(window, bg="#538E6D",bd=1, relief=SUNKEN)
frame.pack()
premier = Entry(frame, text="Entrez votre lore", font=("Courrier",15),bg="#538E6D",fg="white", width=100)
premier.pack(side="top")
# Creation Bouton
bouton= Button(frame, text="Transformez votre lore", font=("Courrier",40),bg="white",fg=color)
bouton.pack(pady=25, fill=X)
# Creation frame 2
frame2 = Frame(window, bg="#538E6D",bd=1, relief=SUNKEN)
frame2.pack()
label = Label(frame2)
label.pack()
# Creation sortie
premier2 = Entry(frame2, text="Voici votre résultat", font=("Courrier",15),bg="#538E6D",fg="white", width=100)
premier2.pack(side="top")
window.mainloop()
这是我尝试过的代码
from lore_hb_fenetre import generate_lore
# Creation fenetre
window = Tk()
color="#538E6D"
window.title("Orym")
window.geometry("720x480")
window.config(background='#538E6D')
# Creation frame avec text
frame = Frame(window, bg="#538E6D",bd=1, relief=SUNKEN)
frame.pack()
premier = Entry(frame, text="Entrez votre lore", font=("Courrier",15),bg="#538E6D",fg="white", width=100)
premier.pack(side="top")
# Creation Bouton
bouton= Button(frame, text="Transformez votre lore", font=("Courrier",40),bg="white",fg=color,command=generate_lore(premier.get()))
bouton.pack(pady=25, fill=
label = Label(frame2)
label.pack()
# Creation sortie
premier2 = Entry(frame2, text=result, font=("Courrier",15),bg="#538E6D",fg="white", width=100)
premier2.pack(side="top")
window.mainloop()X)
# Creation frame 2
frame2 = Frame(window, bg="#538E6D",bd=1, relief=SUNKEN)
frame2.pack()
(这是预期的结果) https://cdn.discordapp.com/attachments/429923253721497612/583268530728730625/unknown.png