Python Tkinter samples – Document Viewer

# Document Viewer
# Designed to view documents

from Tkinter import *
import tkFileDialog

master = Tk()
master.geometry("900x600")
master.title("Document Viewer")

def open_command():
	file = tkFileDialog.askopenfile(mode='rb',title="Select desired file")
	if file != None:
		contents = file.read()
		contents_display = Text(width=900)
		contents_display.delete(1.0, END)
		contents_display.insert(END, contents)
		contents_display.config(state='disabled')
		contents_display.pack()
		file.close()
		

open_document = Button(text="Open Document", command=open_command)
open_document.pack()

master.mainloop()

Only works in Python 2 at the moment, but will be ported over to Python 3.5 soon.

I hope you like my sample!

Epic Chas Gamer 😎

2 thoughts on “Python Tkinter samples – Document Viewer

Go on, you know you want to! Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s