您好,我是论坛的新手。
我有很多使用 python 的经验,但没有使用 tkinter。
这是我的代码:
from tkinter import *
def Done():
celEntry = celTempVar.get()
print(str(celEntry))
f = open("Name", "w")
f.write(str(celEntry))
f.close()
def Yes():
celEntry = Entry (mainframe, width = 10, bd = 5, textvariable = celTempVar)
celEntry.grid(row = 3, column = 1, pady = 10, sticky = NW, padx = 125 )
titleLabel = Label (mainframe, text = "Enter Name", font = ("Arial", 12, "bold"), justify = LEFT)
titleLabel.grid(row = 2, column = 1, columnspan = 3, pady = 10, padx = 20)
DoneButton = Button (mainframe, text = "Done", font = ("Arial", 8, "bold"), relief = RAISED, bd=5, justify = CENTER, highlightbackground = "red", overrelief = GROOVE, activebackground = "black", activeforeground="blue", command = Done)
DoneButton.grid(row = 4, column = 1, ipady = 8, ipadx = 12, pady = 5, sticky = NW, padx = 55)
###MAIN###
root = Tk()
root.title("Text Adv")
mainframe = Frame(root)
mainframe.grid()
celTempVar = StringVar()
celTempVar.set("")
titleLabel = Label (mainframe, text = "Text adventure", font = ("Arial", 20, "bold"), justify = CENTER)
titleLabel.grid(row = 1, column = 1, columnspan = 3, pady = 10, padx = 20)
f = open("Name", "r")
Name = f.read()
if Name == "":
celEntry = Entry (mainframe, width = 10, bd = 5, textvariable = celTempVar)
celEntry.grid(row = 3, column = 1, pady = 10, sticky = NW, padx = 125 )
titleLabel = Label (mainframe, text = "Enter Name", font = ("Arial", 12, "bold"), justify = LEFT)
titleLabel.grid(row = 2, column = 1, columnspan = 3, pady = 10, padx = 20)
DoneButton = Button (mainframe, text = "Done", font = ("Arial", 8, "bold"), relief = RAISED, bd=5, justify = CENTER, highlightbackground = "red", overrelief = GROOVE, activebackground = "black", activeforeground="blue", command = Done)
DoneButton.grid(row = 4, column = 1, ipady = 8, ipadx = 12, pady = 5, sticky = NW, padx = 55)
else:
titleLabel = Label (mainframe, text = "Start new game?", font = ("Arial", 12, "bold"), justify = LEFT)
titleLabel.grid(row = 2, column = 1, columnspan = 3, pady = 10, padx = 20)
DoneButton = Button (mainframe, text = "Yes", font = ("Arial", 8, "bold"), relief = RAISED, bd=5, justify = CENTER, highlightbackground = "red", overrelief = GROOVE, activebackground = "black", activeforeground="blue", command = Yes)
DoneButton.grid(row = 3, column = 1, ipady = 8, ipadx = 12, pady = 5, sticky = NW, padx = 55)
DoneButton = Button (mainframe, text = "No", font = ("Arial", 8, "bold"), relief = RAISED, bd=5, justify = CENTER, highlightbackground = "red", overrelief = GROOVE, activebackground = "black", activeforeground="blue", command = Done)
DoneButton.grid(row = 4, column = 1, ipady = 8, ipadx = 12, pady = 5, sticky = NW, padx = 55)
root.mainloop()
所以我想要的是在运行 Yes() 时鞭打屏幕。
很简单,但对于所有其他答案,我真的不明白。
如果您可以在我的代码中实现擦除功能,那就太好了。
Atm 我只是在试验其他人的代码,所以这就是为什么变量名是 CeltoFar 之类的东西。
如果您不明白,我的意思是从 gui 中删除所有小部件,或者删除特定小部件。
请不要留下任何仇恨!
谢谢
是的,我喜欢新段落:)