
May 6th, 2008, 06:22 AM
|
|
Registered User
|
|
Join Date: May 2008
Posts: 1
Time spent in forums: 31 m 13 sec
Reputation Power: 0
|
|
|
GUI Tkinter - Background image on main app
Hey there, just needing some help with python GUI using tk! just want to know how I can put a picture as a background for my GUI app. I did a search on google for some examples! found one but didnt quite get it to work. My script is a simple one and still learning this python thing.
Code:
from Tkinter import *
import tkMessageBox
import urllib, os, urllib2, httplib
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def visit(self):
visiturl = self.url_ent.get()
request = urllib2.Request(visiturl)
httplib.HTTPConnection.debuglevel = 1
opener = urllib2.build_opener()
feeddata = opener.open(request).read()
print feeddata
def about(self):
tkMessageBox.showinfo("Jedi",'''
Jedi
++++++++++++++++++++++++++++++++++++++++
Jedi Rulz''')
def close(self):
root.destroy()
def history(self):
tkMessageBox.showinfo("Pyge Visitor",'''
No History
+++++++++++++++++++++++++++++++++++++++
Testing
Date: 10/03/2008''')
def create_widgets(self):
# Menubar
menubar = Menu(self)
filemenu = Menu(menubar, tearoff = 0)
filemenu.add_command(label = "History", command=self.history)
filemenu.add_separator()
filemenu.add_command(label = "Close", command=root.quit)
menubar.add_cascade(label = "File", menu = filemenu)
root.config(menu=menubar)
helpmenu = Menu(menubar, tearoff = 0)
helpmenu.add_command(label = "About", command=self.about)
menubar.add_cascade(label = "Help", menu = helpmenu)
# create the label for instructions
self.ins_lbl = Label(self, text = "Enter Your Pyge:")
self.ins_lbl.grid(row = 0, column = 0, columnspan = 3, sticky = NW)
# create entry for url
self.url_ent = Entry(self, width = 29)
self.url_ent.grid(row = 1, column = 1, columnspan = 3, pady = 2, padx = 5)
# create label for url
self.url_lbl = Label(self, text = "URL :")
self.url_lbl.grid(row = 1, column = 0, sticky = NW)
# create visit button
self.cust_bttn = Button(self, text = "Visit",command=self.visit)
self.cust_bttn.grid(row = 4, column = 0, columnspan = 3, sticky = N, padx = 3, pady = 5)
root = Tk()
root.title("Jedi")
root.geometry( "250x100+300+200")
root.resizable(0,0)
app = Application(root)
root.mainloop()
The above is my script and its a GUI app, just want to put a picture background. The code below is the example I found:
Code:
import Tkinter as tk
root = tk.Tk ()
root.title('image hard')
# pick a .gif image file you have in the working directory
image1 = tk.PhotoImage(file="something.gif")
w = image1.width()
h = image1.height()
root.geometry("%dx%d+0+0" % (w, h))
# tk.Frame has no image argument
# so use a label as a panel/frame
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')
button2 = tk.Button(panel1, text='button2')
button2.pack(side='right')
#save the panel's image from 'garbage collection
panel1.image = image1
#start the even loop
root.mainloop()
Any help would be appreciated, thank you
|