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 😎

One lovely blog award – who are my favourite bloggers?

This challenge has spread across the internet like fire (I didn’t create this challenge) so I have decided to do one. Basically, I have to tell you 7 things about my character. And up to 15 bloggers I enjoy. I have over 40 followers, but as there are limits (a few don’t have blogs) and you can only do up to 15. I am sorry if I do not include you!

So, here are the 7 things about me!

1. I think about my web browser project, ECG SeaSurf , for a lot of my time. I love it because the world wide web is a big place, and making software that allows people to browse such a great thing makes me feel special.

2. I do not try to block the spotlight from other developers as I love seeing what others have produced too, and I love getting inspired.

3. I love playing video games because they are extremely fun, and it feels like I am in the game (no VR here!). They also take stress away.

4. I love writing stories, to entertain people. I am writing a story called Sir Wolf’s Castle, about Minecraft wolves and a villan called Sir Bum-Smacker.

5. I love looking at over blogs and leaving feedback and liking posts because I don’t want to look selfish.

6. I love ketchup. It is an awesome sauce.

7. There are lots of other things I love but don’t blog about: Star Wars and Legends of Chima, for example.

Now, here are my favourite bloggers: I DO NOT ACCEPT RESPONSIBILITY FOR LINK CONTENT CHANGING

1. Codeinfig:

An author of a coding language called Fig, a coding enthusiast, and much more. Check out his blog at codeinfig.wordpress.com!

2. Jacque:

If you want to go beyond my app-making service (I would recommend trying it first and requesting a removal if you don’t like it), then Jacque is the person for you. He can even get your app published to the Play Store (I didn’t ask for an app because I can make one myself).

Check out his blog at themarvelousmind.com

3.  ARJ

If you want a guide to coding and you want to be a pro, then ARJ’s blog “A bit of everything – copy” is the place for you. He has another blog, pythongr.wordpress.com, which is worth checking out too.

Find his main blog at abdurrahmaanjanhangeer.wordpress.com

4. Daniel He hetianding

A Minecraft enthusiast, this blogger creates maps and then publishes them.

Find his blog at worldofmanyworlds.wordpress.com.

5. LZH

A real tech enthusiast, admin of a website called TechCentral which contains everything tech.

Leave a comment or like at limzhenghong.wordpress.com

6. AntonioWestley

A master blogger, who loves posting about sites he recommends.

Check out his active site at alltheeabove.wordpress.com.

Check out his inactive site at antoniowestley.wordpress.com

7. antepher

A real ESP8266 and Arduino enthusiast, as well as Python Expert, antepher maintains a blog called techtutorialsx.

Like and comment on his blog at techtutorialsx.wordpress.com!

8. Paul Sinha

One of my first followers, Paul Sinha appears on the Chase and is really funny.

Check out his blog at sinhaha.com

9. Old and New Reviews

Reviewing and playing video games, I enjoy reading this blog.

Follow the blog at oldandnewreviews.com!

10. Is there any blog you recommend?

I can’t think of a tenth, but I want to reach 10, so if you recommend a blog, plz leave  a comment.

PS: The rules (I have forgotten the URL to the original creator’s blog) also mention that you should post about being chosen. So, thank you codeinfig for choosing me! SO, remember that!

Epic Chas Gamer 😀

 

 

 

Python, GTK and WebKit – creating a web browser – Part 3

Hey guys! Welcome to Part 3 of my Python, GTK and WebKit – creating a web browser tutorial. Part 3 will show you how to add an “About” button to the browser. The about dialog will look like:

aboutbasic

Add the following few lines to the beginning of the code:

import Tkinter
from ScrolledText import *
import tkFileDialog
import tkMessageBox

Then we add the About button and dialog and all that. Here is the finished code for Part 3:

#!/usr/bin/env python
import gtk, webkit, os, pickle
import Tkinter
from ScrolledText import *
import tkFileDialog
import tkMessageBox

class Basic():

def __init__(self):
self.window = gtk.Window()
self.window.connect(‘destroy’, lambda w: gtk.main_quit())
self.window.set_default_size(640, 480)

self.navigation = gtk.HBox()
self.refresh = gtk.ToolButton(gtk.STOCK_REFRESH)
self.address_bar = gtk.Entry()
self.gobutton = gtk.Button(“GO!”)
self.about = gtk.ToolButton(gtk.STOCK_DIALOG_INFO)

self.view = gtk.ScrolledWindow()
self.webview = webkit.WebView()
self.webview.open(‘http://google.com/’)
self.webview.connect(‘title-changed’, self.change_title)
self.webview.connect(‘load-committed’, self.change_url)
self.view.add(self.webview)

self.refresh.connect(‘clicked’, self.refresh_page)
self.address_bar.connect(‘activate’, self.load_page)
self.gobutton.connect(‘clicked’, self.load_page)
self.about.connect(‘clicked’, self.about_browser)
self.navigation.pack_start(self.refresh, False)
self.navigation.pack_start(self.address_bar)
self.navigation.pack_start(self.gobutton, False)
self.navigation.pack_start(self.about, False)
self.container = gtk.VBox()
self.container.pack_start(self.navigation, False)
self.container.pack_start(self.view)

self.window.add(self.container)
self.window.show_all()
gtk.main()

def load_page(self, widget):
add = self.address_bar.get_text()
if add.startswith(‘http://’) or add.startswith(‘https://’) or add.startswith(‘file:///’):
self.webview.open(add)
else:
add = ‘http://’ + add
self.address_bar.set_text(add)
self.webview.open(add)

def about_browser(self, widget):
root = Tkinter.Tk(className=””)
SeaSurfAbout = ScrolledText(root, width=50, height=50)
label = tkMessageBox.showinfo(“”, “Basic Web Browser \n Version 1.0″)
root.destroy()

def change_title(self, widget, frame, title):
self.window.set_title(title + ” – Basic Web Browser”)

def change_url(self, widget, frame):
uri = frame.get_uri()
self.address_bar.set_text(uri)

def refresh_page(self, widget):
self.webview.reload()
browser = Basic()

I wonder what is in store for part 4?

Epic Chas Gamer 😀

Python, GTK and WebKit – creating a web browser – Part 2

IF YOU HAVE NOT YET, PLEASE READ PART 1 BEFORE CONTINUING!

In Part 1, I showed you how to create a very basic web browser in Python with WebKit and GTK. It is a great example of Python’s power, but there was no refresh button. Part 2 focuses on adding this feature so you can refresh unresponsive pages.

First, load up the Python script you created in Part 1 and find the lines:

self.address_bar = gtk.Entry()
self.gobutton = gtk.Button(“GO!”)

And put the following above self.address_bar = gtk.Entry()

self.refresh = gtk.ToolButton(gtk.STOCK_REFRESH)

Then find the

self.address_bar.connect(‘activate’, self.load_page)
self.gobutton.connect(‘clicked’, self.load_page)

…and put the following above self.address_bar.connect(‘activate’, self.load_page):

self.refresh.connect(‘clicked’, self.refresh_page)

Eh, what is going on here! The variable self.refresh_page doesn’t even exist. Well, it doesn’t yet. We will later add that variable so you can run this program without errors.

Now, find the lines:

self.navigation.pack_start(self.address_bar)
self.navigation.pack_start(self.gobutton, False)

And add the following above self.navigation.pack_start(self.address_bar):

self.navigation.pack_start(self.refresh, False)

Now find:  def change_url(self, widget, frame):
uri = frame.get_uri()
self.address_bar.set_text(uri) and press enter beneath it. If you are using a Python IDE, then press enter twice then backspace once.

Now add the following lines:

def refresh_page(self, widget):
self.webview.reload()

Now we have finished Part 2 of your basic browser. I am thinking of what to show you in Part 3 currently, but I am sure it will be awesome!

The finished code:

finished2

#!/usr/bin/env python
import gtk, webkit, os, pickle

class Basic():

def __init__(self):
self.window = gtk.Window()
self.window.connect(‘destroy’, lambda w: gtk.main_quit())
self.window.set_default_size(640, 480)

self.navigation = gtk.HBox()
self.refresh = gtk.ToolButton(gtk.STOCK_REFRESH)
self.address_bar = gtk.Entry()
self.gobutton = gtk.Button(“GO!”)

self.view = gtk.ScrolledWindow()
self.webview = webkit.WebView()
self.webview.open(‘http://google.com/’)
self.webview.connect(‘title-changed’, self.change_title)
self.webview.connect(‘load-committed’, self.change_url)
self.view.add(self.webview)

self.refresh.connect(‘clicked’, self.refresh_page)
self.address_bar.connect(‘activate’, self.load_page)
self.gobutton.connect(‘clicked’, self.load_page)
self.navigation.pack_start(self.refresh, False)
self.navigation.pack_start(self.address_bar)
self.navigation.pack_start(self.gobutton, False)

self.container = gtk.VBox()
self.container.pack_start(self.navigation, False)
self.container.pack_start(self.view)

self.window.add(self.container)
self.window.show_all()
gtk.main()

def load_page(self, widget):
add = self.address_bar.get_text()
if add.startswith(‘http://’) or add.startswith(‘https://’) or add.startswith(‘file:///’):
self.webview.open(add)
else:
add = ‘http://’ + add
self.address_bar.set_text(add)
self.webview.open(add)

def change_title(self, widget, frame, title):
self.window.set_title(title + ” – Basic Web Browser”)

def change_url(self, widget, frame):
uri = frame.get_uri()
self.address_bar.set_text(uri)

def refresh_page(self, widget):
self.webview.reload()
browser = Basic()

 

Here is what our browser looks like now 🙂

basicbrowser2

Hope you like it!

Cheers!

Epic Chas Gamer 😀

 

 

 

 

 

 

Python, GTK and WebKit – creating a web browser – Part 1

THIS WEB BROWSER IS NOT SEASURF. IT IS A VERY BASIC BUT RATHER FUNCTIONAL WEB BROWSER. 

Here is how to use Python, GTK and WebKit to create a very simple web browser.

First, you will need Python and the GTK and WebKit modules installed.

Here is the code for the basic web browser:

#!/usr/bin/env python
import gtk, webkit, os, pickle

class Basic():

def __init__(self):
self.window = gtk.Window()
self.window.connect('destroy', lambda w: gtk.main_quit())
self.window.set_default_size(640, 480)

self.navigation = gtk.HBox()

self.address_bar = gtk.Entry()
self.gobutton = gtk.Button("GO!")

self.view = gtk.ScrolledWindow()
self.webview = webkit.WebView()
self.webview.open('https://coolchasgamer.wordpress.com')
self.webview.connect('title-changed', self.change_title)
self.webview.connect('load-committed', self.change_url)
self.view.add(self.webview)

self.address_bar.connect('activate', self.load_page)
self.gobutton.connect('clicked', self.load_page)

self.navigation.pack_start(self.address_bar)
self.navigation.pack_start(self.gobutton, False)

self.container = gtk.VBox()
self.container.pack_start(self.navigation, False)
self.container.pack_start(self.view)

self.window.add(self.container)
self.window.show_all()
gtk.main()

def load_page(self, widget):
add = self.address_bar.get_text()
if add.startswith('http://') or add.startswith('https://') or add.startswith('file:///'):
self.webview.open(add)
else:
add = 'http://' + add
self.address_bar.set_text(add)
self.webview.open(add)

def change_title(self, widget, frame, title):
self.window.set_title(title + " - Basic Web Browser")

def change_url(self, widget, frame):
uri = frame.get_uri()
self.address_bar.set_text(uri)

browser = Basic()

The result:

basicbrowser

Enjoy!

Epic Chas Gamer 😀

Python: Input

Use raw_input for this. Here is an example:

print(“Raw_Input example, by Epic Chas Gamer”)

name = raw_input(“What is your name? “)

print(“Hello, “,name)

If you get errors plz comment 🙂

What do you really want to see in ECG SeaSurf?

I have came up with a name for the web browser I am developing. I am calling it SeaSurf. What features do you really want in SeaSurf. I will try my hardest to add the features to ECG SeaSurf, but I can’t guarantee.

You can vote for more than one feature!

Have a nice day!

Epic Chas Gamer 😀