I am new to programming and python so I thank you in advance for your patience.
I have created a class which creates a new window with a test image for it’s background (“test1.gif”).
I have also created a drop down menu within the same class that lets you choose between 3 countries.
I can comment off either the code that makes the background or the code that makes the menu and the other will display. However I want the menu to appear above the background. When I run the full code I only see the background.
I appreciate I am probably missing something very obvious here, if some one could please point out what that is.
Thanks for your time.
Dan
from Tkinter import *
import Tkinter as tk
class dropDown():
def __init__(self, master):
#background set_up
image1 = tk.PhotoImage(file="test1.gif")
w = image1.width()
h = image1.height()
root.geometry("%dx%d+0+0" % (w, h))
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')
# save the panel's image from 'garbage collection'
panel1.image = image1
#Drop down menu
self.var = StringVar(master)
self.var.set('Alaska') # initial value
#Have not used countries list just pasted
self.option = OptionMenu(master, self.var, 'Alberta', 'Australia')
self.option.pack()
root = Tk()
root.title('drop down test')
dropDown(root)
mainloop()
(I think) Your problem is that you’re restricting the size of the root window to be the size of the image (instead of the sizeof(image)+sizeof(menu)). This fixes the problem for me on OS-X.
A side note, it would be very easy to have your dropDown inherit from Frame and then adjust the size of your Frame (Although it probably isn’t necessary). Then you can move this widget anywhere you want to on the GUI.
EDIT
subclassing Frame:
Note that now Tkinter/TK take care of all the frame resizing for you. 🙂