Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从Tkinter中删除文本?_Python_Tkinter - Fatal编程技术网

Python 如何从Tkinter中删除文本?

Python 如何从Tkinter中删除文本?,python,tkinter,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':

我想知道你如何删除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()
    
    myLabel.destroy()