-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopen_file.py
More file actions
37 lines (31 loc) · 1.07 KB
/
open_file.py
File metadata and controls
37 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from tkinter import *
from tkinter import filedialog
# Functions
def uploadFile():
filePath = filedialog.askopenfilename(initialdir="C:\\Users\\ADMIN\\OneDrive\\Desktop",
title="Select Text File",
filetypes=(("Text Files", "*.txt"), ("Python Files", "*.py")))
# with open(filePath) as f:
# data = f.read()
if filePath != "":
fileData = open(filePath).read()
print(fileData)
else: print("No file was selected.")
# Creating Window
window = Tk()
# Styling Window
window.title("Open File Program Tkinter")
window.geometry("400x700")
window.config(bg="black")
# Creating Button To Upload a File
button = Button(window,
text="Upload File",
command=uploadFile,
font=("Consonatia", 20, "bold"),
padx=10,
pady=10,
bg="light yellow",
activebackground="light yellow")
button.pack()
# Displaying Window
window.mainloop()