import tkinter as tk
root = tk.Tk()
root.title("To Do")
root.geometry("500x750")
root.resizable(False, False)
class App:
def __init__(self, window):
#Button font
self.buttonFont = ("Courier", 13, "normal")
#Header
self.header = tk.Label(text = "To Do List\n", font = ("Helvetica", 26, "bold"))
self.header.grid()
#Add item button
self.addButton = tk.Button(text = "Add Item", font = self.buttonFont, bg = "green", command = self.OpenAddItem)
self.addButton.grid(row = 1, column = 0, )
#Del item button
self.delButton = tk.Button(text = "Delete Item", font = self.buttonFont, bg = "red")
self.delButton.grid(row = 1, column = 1, )
#items frame and stuff
self.itemsframe = tk.Frame()
self.itemsframe.grid(row = 2)
self.item = tk.Label(self.itemsframe, font = ("Helvetica", 11, "normal"))
def OpenAddItem(self):
#COnfiguring prompt win
self.addPromptWin = tk.Toplevel(root)
self.addPromptWin.title("Prompt")
self.addPromptWin.geometry("375x100")
self.addPromptWin.resizable(False,False)
#Entry label
self.entryLabel = tk.Label(self.addPromptWin,text = "Enter item name:", font = ("Courier", 11, "normal"))
self.entryLabel.grid(sticky = tk.E)
#Adding entry
self.entry = tk.Entry(self.addPromptWin, font = ("Courier", 11, "normal"))
self.entry.grid(row = 0, column = 1)
self.entry.bind("<Return>", lambda e: self.AddItem())
#Add new item button
self.addNewItemButton = tk.Button(self.addPromptWin, text = "Add", font = self.buttonFont, bg = "green", command = self.AddItem)
self.addNewItemButton.grid(row = 1, sticky = tk.W)
大家好,我的 tkinter gui 程序有问题。当我调用 addItem 函数时,它不是每次都创建一个新标签,而是替换当前标签。任何帮助将非常感激!
慕码人2483693
相关分类