Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How does .configure() and .pack() work together in Tkinter?

Currently trying to work with GUI’s and i am having the problem, that as soon as i format a label with .pack() i can’t use .configure() on the same label to change its text.

def browseFiles():
    global filename
    filename = filedialog.askopenfilename(initialdir = "/Desktop",
                                          title = "Explorer",
                                          filetypes = (("Pics",
                                                         "*.jpg*"),
                                                       ("Text",
                                                        "*.txt*"),
                                                       ("All",
                                                        "*.*")))
      
    f = open("yeet.txt", "a")
    f.write(filename)
    f.close()
    label_file_explorer.configure(text="You chose: "+filename)

The label itself looks like this:

label_file_explorer = Label(window,text = "Label",width = 100, height = 4,fg = "blue").pack()

As soon as i leave the .pack() out i can’t see the label, but i don’t get an error, so i’d assume it works.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

FYI – this is the error message: ‘NoneType’ object has no attribute ‘configure’

>Solution :

I believe that the .pack() method returns the None you are seeing.

I think what you meant was this:

label_file_explorer = Label(window,text = "Label",width = 100, height = 4,fg = "blue")
label_file_explorer.pack()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading