Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter - way to open a directory window in Windows Explorer

I've been looking into Tkinter and recently have made a small program just to monitor folders and check how many files are inside.

I'de like to create buttons that open the folders in Windows Explorer but I can't find any info on doing so.

Anyone got any Ideas?

Cheers, Jon

Thanks for the quick response I'd already tried something similar but I'm probably doing something wrong. Here's my code :

def open():
    os.system("explorer C:\\ folder dir")

label1 = Button(self, text="Pre TC", fg="red", font=("Ariel", 9, "bold"), command=open)
like image 923
Jon.H Avatar asked Oct 27 '25 03:10

Jon.H


1 Answers

self has to be used when you are calling a function defined under the same class name of which label1 or button1 is an object. Otherwise you get the Tkinter callback exception as the function is not found.

That is why renaming open to self.open works

like image 65
nihal111 Avatar answered Oct 29 '25 17:10

nihal111



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!