如何从Tkinter删除文本?

问题描述 投票:-1回答:1

我想知道您如何删除Tkinter中的文本。文本以红色圈出。

我的代码如下:

从tkinter导入*

从tkinter.ttk导入组合框

导入win32com.client

root = Tk()

root.title('PM1数字清单')

root.geometry(“ 400x400”)

def open_excel():

if combo.get() == 'PPM8001':
    myLabel = Label(root, text="Prime Mover Number Selected is:").pack()
    myLabel = Label(root, text=combo.get()).pack()
    excel = win32com.client.Dispatch("Excel.Application")
    excel.Visible = True
    file = excel.Workbooks.Open(r"C:\Users\attjngy1\Downloads\PM1 Checklist\PPM8001-8036\PPM8001.xlsx")

if combo.get() == 'PPM8002':
    myLabel = Label(root, text="Prime Mover Number Selected is:").pack()
    myLabel = Label(root, text=combo.get()).pack()
    excel = win32com.client.Dispatch("Excel.Application")
    excel.Visible = True
    file = excel.Workbooks.Open(r"C:\Users\attjngy1\Downloads\PM1 Checklist\PPM8001-8036\PPM8002.xlsx")

if combo.get() == 'PPM8003':
    myLabel = Label(root, text="Prime Mover Number Selected is:").pack()
    myLabel = Label(root, text=combo.get()).pack()
    excel = win32com.client.Dispatch("Excel.Application")
    excel.Visible = True
    file = excel.Workbooks.Open(r"C:\Users\attjngy1\Downloads\PM1 Checklist\PPM8001-8036\PPM8003.xlsx")

选项= ['PPM8001','PPM8002','PPM8003']

v =列表(选项)

combo =组合框(根,值= v,宽度= 40)

combo.set(“选择哪个原动机编号”)

combo.pack()

按钮=按钮(根,文本=“选择”,命令= open_excel).pack()

root.mainloop()

图像链接是:https://i.stack.imgur.com/RYS29.png

python tkinter text
1个回答
0
投票

有2处要修复的问题:1)使用

myLabel = Label(root, text="Prime Mover Number Selected is:")
myLabel.pack()

将标签实例实际放入变量中2)使用

myLabel.destroy()

摆脱它。

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.