23 Python Tkinter Browsing A File

preview_player
Показать описание
Join My PyQt6 13 Hours Course in Udemy

Join Free TKinter Course

My Affiliate Books:
Modern Tkinter for Busy Python Developers PDF Book

This is our twenty third video in Tkinter gui application development with python3 in this video iam going to show you how you can Browse A File in Tkinter

Tkinter Application Development Playlist

Complete Video Tutorial For PyQt5 Application Development

Pyglet Tutorial For Multimedia Applications And Game Development

Python Opengl Programming With Pyopengl

Python For Data Science Playlist

Pyqt5 And Qt Designer Making Rich Text Editor

Developign QtQuick C++ Applications
Рекомендации по теме
Комментарии
Автор

The following code should help some people... (Python 3)




import tkinter
from tkinter import filedialog
import os

root = tkinter.Tk()
root.withdraw() #use to hide tkinter window

def search_for_file_path ():
currdir = os.getcwd()
tempdir = filedialog.askdirectory(parent=root, initialdir=currdir, title='Please select a directory')
if len(tempdir) > 0:
print ("You chose: %s" % tempdir)
return tempdir


file_path_variable = search_for_file_path()
print ("\nfile_path_variable = ", file_path_variable)

shanerooney
Автор

Thank you soo much sir, you help my FYP!!!!

asyikinazmi
Автор

Thanks. This is exactly what I was looking for.

ajas
Автор

thank you a lot! finally a very useful tutorial, helped me a lot, thanks!

Kaliumcyanidful
Автор

How can I then access the selected file and do some processes on that file?? is there a variable or sth?? please help on this!!

alibaghban
Автор

thanks, a lot sir very helpful for my school project i have some more doubts please reply

jerinabrahamissac
Автор

Thanks a lot. I have a doubt How can i save my previous file path

amitdixit
Автор

HI

How can i select the .txt file from current directory using the python from already opened dialog?

anantaggarwal
Автор

how to display the selected image file in form

ascentztechnologies
Автор

import tkinter as tk
from tkinter import filedialog as fd

a=""
str1 = "e"
class Browse(tk.Frame):
""" Creates a frame that contains a button when clicked lets the user to select
a file and put its filepath into an entry.
"""


def __init__(self, master, initialdir='', filetypes=()):
super().__init__(master)
self.filepath = tk.StringVar()
self._initaldir = initialdir
self._filetypes = filetypes
self._create_widgets()
self._display_widgets()

def _create_widgets(self):
self._entry = tk.Entry(self, textvariable=self.filepath, font=("bold", 10))
a=self._entry
self._button = tk.Button(self, text="Browse...", bg="red", fg="white", command=self.browse)
self._classify=tk.Button(self, text="Classify", bg="red", fg="white", command=self.classify)
self._label=tk.Label(self, text="IMAGE CLASSIFICATION USING DEEP LERAINING.", bg="blue", fg="white", height=3, font=("bold", 14))



def _display_widgets(self):

self._label.pack(fill='y')
self._entry.pack(fill='x', expand=True)
self._button.pack(fill='y')
self._classify.pack(fill='y')

def retrieve_input(self):
#str1 = self._entry.get()
#a=a.replace('/', '//')
print (str1)
def classify(self):
newwin = tk.Toplevel(root)
newwin.geometry("500x500")
label = tk.Label(newwin, text="Classification", bg="blue", fg="white", height=3, font=("bold", 14))
label.pack()
canvas = tk.Canvas(newwin, height=300, width=300)
canvas.pack()
my_image = tk.PhotoImage(file=a, master=root)
canvas.create_image(150, 150, image=my_image)
newwin.mainloop()

def browse(self):
""" Browses a .png file or all files and then puts it on the entry.
"""

self.filepath.set(fd.askopenfilename(initialdir=self._initaldir,
filetypes=self._filetypes))


if __name__ == '__main__':
root = tk.Tk()
labelfont = ('times', 10, 'bold')
root.geometry("500x500")
filetypes = (
('Portable Network Graphics', '*.png'),
("All files", "*.*")
)

file_browser = Browse(root, initialdir=r"C:\Users",
filetypes=filetypes)
file_browser.pack(fill='y')
root.mainloop()

zeeshannajeeb
Автор

Its executing on the shell without any errors but not displaying anything

zheelnanda
Автор

how to store the media files into list with extension or path

deepakgautam
Автор

Great video. Thank you. I started learning programming in '78 with Fortran IV and moved to Matlab in the late 90s. I used to write everything as generic subroutines and called each subroutine in a program as needed in order to minimize the size of the main file. Can this be done with Python? For example, writing a program for the menu bar, a program for a calculator, a program for a graphing, and then calling each program in a main program. Is this possible?

baruchba
Автор

I want to load an excel file into GUI app and display data on the gui. How do I do that ?

sjxqhbp
Автор

Can u provide code to select multiple excel file and combine to one dataframe using tkinter

parajf
Автор

How to store that file in database SQL online

AbbyVbz
Автор

I am getting path way as <_io.TextIOWrapper " mode="r">
how to get only path name?

henishshah
Автор

Thank you i used same way to take filenames but somehow file browser dialog doesnt close on background and get heavy on explorer.exe. so my system starts act weird. And program has crashs freezes also windows freezes. Why?

huseyinozker
Автор

i wanna know if i select path of .png image how can i show that image in new window. Please Reply .

zeeshannajeeb
Автор

How can i browse a file or more than 1 type? Lets says jpeg or pdf?

harshasri