Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pressure679/145e3054b0d96658513427861773bf1c to your computer and use it in GitHub Desktop.
Save pressure679/145e3054b0d96658513427861773bf1c to your computer and use it in GitHub Desktop.
from tkinter import *
from tkinter import filedialog
from tkinter import *
from tkinter import ttk
from tkinter.filedialog import askopenfilename
root = Tk()
name = ""
def OpenFile():
name = askopenfilename(initialdir="C:/Users/Batman/Documents/Programming/tkinter/", filetypes =(("Text File", "*.txt"),("All Files","*.*")), title = "Choose a file." )
print (name)
try:
with open(name,'r') as UseFile:
print(UseFile.read())
except:
print("No file exists")
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)
# File opener toolbar part. (browseFile function)
Title = root.title( "File Opener")
label = ttk.Label(root, text ="I'm BATMAN!!!",foreground="red",font=("Helvetica", 16))
label.pack()
menu = Menu(root)
root.config(menu=menu)
file = Menu(menu)
file.add_command(label = 'Open', command = OpenFile)
file.add_command(label = 'Exit', command = lambda:exit())
menu.add_cascade(label = 'File', menu = file)
# file explorer part (OpenFile function)
Title = root.title( "File Opener")
label = ttk.Label(root, text ="I'm BATMAN!!!",foreground="red",font=("Helvetica", 16))
label.pack()
#Menu Bar
menu = Menu(root)
root.config(menu=menu)
file = Menu(menu)
file.add_command(label = 'Open', command = OpenFile)
file.add_command(label = 'Exit', command = lambda:exit())
menu.add_cascade(label = 'File', menu = file)
# Button for shell call
# tkinter.Button(root, text="Push me!", command=lambda: sub.call('path/to/script')).pack()
Button(root, text="Push me!", command=lambda: sub.call(name)).pack()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment