| | |
Tkinter window background
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
sigh...
I need a way to make an image as a background for a window, and still be able to put buttons and other controls on top of it. I even tried using wxPython's wxPanel, but it proved a real pain because I found the documentation very sparce...
(google didn't even help).
Is there anyway I can do this? I've heard about the canvas but I have no idea how to use this...
Thanks.
I need a way to make an image as a background for a window, and still be able to put buttons and other controls on top of it. I even tried using wxPython's wxPanel, but it proved a real pain because I found the documentation very sparce...
(google didn't even help).Is there anyway I can do this? I've heard about the canvas but I have no idea how to use this...
Thanks.
My new machine has Windows Vista OS and I can't get Tkinter to work, but wxPython works fine ...
python Syntax (Toggle Plain Text)
# create a background image on a wxPython panel # and show a button on top of the image import wx class Panel1(wx.Panel): """class Panel1 creates a panel with an image on it, inherits wx.Panel""" def __init__(self, parent, id): # create the panel wx.Panel.__init__(self, parent, id) try: # pick an image file you have in the working folder # you can load .jpg .png .bmp or .gif files image_file = 'roses.jpg' bmp1 = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap() # image's upper left corner anchors at panel coordinates (0, 0) self.bitmap1 = wx.StaticBitmap(self, -1, bmp1, (0, 0)) # show some image details str1 = "%s %dx%d" % (image_file, bmp1.GetWidth(), bmp1.GetHeight()) parent.SetTitle(str1) except IOError: print "Image file %s not found" % imageFile raise SystemExit # button goes on the image --> self.bitmap1 is the parent self.button1 = wx.Button(self.bitmap1, id=-1, label='Button1', pos=(8, 8)) app = wx.PySimpleApp() # create a window/frame, no parent, -1 is default ID # change the size of the frame to fit the backgound images frame1 = wx.Frame(None, -1, "An image on a panel", size=(350, 400)) # create the class instance panel1 = Panel1(frame1, -1) frame1.Show(True) app.MainLoop()
May 'the Google' be with you!
quick question. Can I use Tkinter and wxpython in the same app? (See i built this splash screen class in Tkinter --doesn't use buttons, but does a lot of work (loading images/files/wat not)).
If not, is there a way to remove the title bar and border in wxpython like does in Tkinter?
If not, is there a way to remove the title bar and border in wxpython like
python Syntax (Toggle Plain Text)
root.overideredirect(1)
No, you can not use Tkinter and wxPython in the same application. Their eventloops would clash.
Yes you can remove the title bar from a wx.Frame ...
I finally doctored the Python25 Vista installation to make Tkinter work. Here is a similar code for Tkinter ...
Yes you can remove the title bar from a wx.Frame ...
•
•
•
•
A frame without titlebar:
You can change frame style to wxMINIMIZE_BOX, but now you have
to supply an exit button somewhere.
python Syntax (Toggle Plain Text)
# use a Tkinter label as a panel/frame with a background image # (note that Tkinter reads only GIF and PGM/PPM images) import Tkinter as tk root = tk.Tk() root.title('background image') # pick a .gif image file you have in the working directory image1 = tk.PhotoImage(file="roses.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='top') # save the panel's image from 'garbage collection' panel1.image = image1 # start the event loop root.mainloop()
May 'the Google' be with you!
![]() |
Similar Threads
- Transparent letters in Tkinter? (Python)
- Tkinter Window Full Size (Python)
- Center a Tkinter Window (Python)
- Tkinter Window Fixed Size (Python)
- New IE window (Web Browsers)
Other Threads in the Python Forum
- Previous Thread: Disabling the title bar?
- Next Thread: Python/Tkinter Imagebutton using Base64
| Thread Tools | Search this Thread |
accessdenied advanced application argv beginner change code command convert csv cursor def dictionary digital dynamic dynamically edit editing enter event examples excel file float format frange function google gui homework i/o import input jaunty java keyboard lapse line linux list lists loop microphone mouse movingimageswithpygame newb number numbers obexftp output parameters parsing path port prime programming projects py2exe pygame pygtk pyopengl python random recursion remote return reverse scrolledtext session simple skinning smtp sprite stderr string strings strip subprocess syntax table tennis terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode unit urllib urllib2 variable voip web-scrape windows wxpython






