Hi just wonderin if anyone can help with my GUI, I got this far, but want to have an image on the background of the main app, and also the buttons. Ive read through vegaseat's script which he helped someone on here, but somehow I can implement his code into mine (or workout how to script it in a way to work for my code), Ive tried but still failed lol, Im a newb, so sorry if this is a easy question (still learning). So if anyone can show me how and can take the time to explain (in layman term) I would much appreciate it! thank you

from Tkinter import *
import tkMessageBox
import urllib, os, urllib2, httplib

class Application(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)

    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):
        Jedi Rulz''')

    def close(self):

    def history(self):
        tkMessageBox.showinfo("Pyge Visitor",'''
        No History  
        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_command(label = "Close", command=root.quit)
        menubar.add_cascade(label = "File", menu = filemenu)
        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 URL:")
        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 visi 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.geometry( "250x100+300+200")
app = Application(root)

Vegaseats code that I looked at (below)

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')

#save the panel's image from 'garbage collection
panel1.image = image1

#start the even loop

Recommended Answers

All 2 Replies

Images can be a slight pain in Tkinter because only certain formats are supported. The work-around is to install Python Imaging Library, PIL. So: what image formats do you have?

And, where do you want the images to go? I couldn't quite tell from the code.

Also, are you trying to make a custom web-browser?


Vegaseat has given Tkinter a namspace tk. Good coding practice to avoid method collisions, and to tell folks that read your code where the method came from. Is that what's confusing to you?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.