Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to upload file in python tkinter

# Python program to create
# a file explorer in Tkinter
  
# import all components
# from the tkinter library
from tkinter import *
  
# import filedialog module
from tkinter import filedialog
  
# Function for opening the
# file explorer window
def browseFiles():
    filename = filedialog.askopenfilename(initialdir = "/",
                                          title = "Select a File",
                                          filetypes = (("Text files",
                                                        "*.txt*"),
                                                       ("all files",
                                                        "*.*")))
      
    # Change label contents
    label_file_explorer.configure(text="File Opened: "+filename)
      
      
                                                                                                  
# Create the root window
window = Tk()
  
# Set window title
window.title('File Explorer')
  
# Set window size
window.geometry("500x500")
  
#Set window background color
window.config(background = "white")
  
# Create a File Explorer label
label_file_explorer = Label(window,
                            text = "File Explorer using Tkinter",
                            width = 100, height = 4,
                            fg = "blue")
  
      
button_explore = Button(window,
                        text = "Browse Files",
                        command = browseFiles)
  
button_exit = Button(window,
                     text = "Exit",
                     command = exit)
  
# Grid method is chosen for placing
# the widgets at respective positions
# in a table like structure by
# specifying rows and columns
label_file_explorer.grid(column = 1, row = 1)
  
button_explore.grid(column = 1, row = 2)
  
button_exit.grid(column = 1,row = 3)
  
# Let the window wait for any events
window.mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: pd merge on multiple columns 
Python :: python filter 
Python :: create virtualenv in linux python 
Python :: delete unnamed coloumns in pandas 
Python :: python get names of all classes 
Python :: pandas replace zero with blank 
Python :: how to hide command console python 
Python :: discord.py cog 
Python :: swapcase 
Python :: how to increase bar width in python matplogtlib 
Python :: python get system information 
Python :: get os information python 
Python :: python join list to string 
Python :: python candlestick chart 
Python :: how to make a pythoon turtle follow another? 
Python :: decrease hours in datetime python 
Python :: one hot encoding numpy 
Python :: find a file in python 
Python :: how to redirect in flask to the same page 
Python :: count values pandas 
Python :: new in python 
Python :: django making a custom 403 page 
Python :: python get current month 
Python :: blank=True 
Python :: save a file as a pickle 
Python :: create a role with discord.py 
Python :: last history of whatsapp message with python 
Python :: print % in python 
Python :: python how to change an element in a multi dimensional list 
Python :: how to do md5 hASH IN PYTHON 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =