Changing the text on a label

前端 未结 6 1510
长情又很酷
长情又很酷 2020-11-28 10:43

I am having trouble with using a key binding to change the value of a label or any parameter. This is my code:

from tkinter import*

class MyGUI:
  def __ini         


        
6条回答
  •  难免孤独
    2020-11-28 10:50

    I made a small tkinter application which is sets the label after button clicked

    #!/usr/bin/env python
    from Tkinter import *
    from tkFileDialog import askopenfilename
    from tkFileDialog import askdirectory
    
    
    class Application:
        def __init__(self, master):
            frame = Frame(master,width=200,height=200)
            frame.pack()
    
            self.log_file_btn = Button(frame, text="Select Log File", command=self.selectLogFile,width=25).grid(row=0)
            self.image_folder_btn = Button(frame, text="Select Image Folder", command=self.selectImageFile,width=25).grid(row=1)
            self.quite_button = Button(frame, text="QUIT", fg="red", command=frame.quit,width=25).grid(row=5)
    
            self.logFilePath =StringVar()
            self.imageFilePath = StringVar()
            self.labelFolder = Label(frame,textvariable=self.logFilePath).grid(row=0,column=1)
            self.labelImageFile = Label(frame,textvariable = self.imageFilePath).grid(row = 1,column=1)
    
            def selectLogFile(self):
                filename = askopenfilename()
                self.logFilePath.set(filename)
    
            def selectImageFile(self):
                imageFolder = askdirectory()
                self.imageFilePath.set(imageFolder)
    
    root = Tk()
    root.title("Geo Tagging")
    root.geometry("600x100")
    app = Application(root)
    root.mainloop()
    

提交回复
热议问题