python - 如何从 Tkinter 中删除文本?
问题描述
我想知道你如何删除 Tkinter 中的文本。文字以红色圈出。
我的代码如下:
from tkinter import *
from tkinter.ttk import Combobox
import win32com.client
root = Tk()
root.title('PM1 Digital Checklist')
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"/path/to/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"/path/to/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"/path/to/PPM8003.xlsx")
options = ['PPM8001','PPM8002','PPM8003']
v = list(options)
combo = Combobox(root, values = v, width =40)
combo.set("Select which Prime Mover number")
combo.pack()
button = Button(root, text = "Select", command = open_excel).pack()
root.mainloop()
图片在这里:
解决方案
有两件事要解决:
- 利用
myLabel = Label(root, text="Prime Mover Number Selected is:")
myLabel.pack()
将 Label 实例实际放入变量中
- 利用
myLabel.destroy()
摆脱它。
希望这会有所帮助!
推荐阅读
- c# - 如何在 ASP.NET Core Web API 中添加两个不同的令牌
- mysql - Update large amount of data in SQL database via Airflow
- c# - How can adding certificate to the trusted root certificates
- flutter - 图像未显示在 Flutter Splash Screen 页面中
- typescript - 如何实现通用的第一个“case/switch”类型
- linux - 有没有办法通过 linux 上的命令行在 docker 上启用 kubernetes?
- regex - 从 CSV 文件中读取的 Perl 第一行与 ^ regex 不正确匹配
- html - POWERSHELL - 三个不同长度的数组,如何创建具有 3 列的 HTML 输出?
- zapier - 需要在 Zapier 中使用代码步骤操作订单项的结果
- elasticsearch - 如何在 Elastic Search 查询字符串请求中获得最终分数的总和?