Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:18:45+00:00 2026-06-05T18:18:45+00:00

I am new to programming and python so I thank you in advance for

  • 0

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()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:18:47+00:00Added an answer on June 5, 2026 at 6:18 pm

    (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.

    import Tkinter as tk
    
    class dropDown():
        def __init__(self, master):
    
            #background set_up
            image1 = tk.PhotoImage(file="test.gif")
            w = image1.width()
            h = image1.height()
            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 = tk.StringVar(master)
            self.var.set('Alaska') # initial value
    
            #Have not used countries list just pasted
            self.option = tk.OptionMenu(master, self.var, 'Alaska','Alberta', 'Australia')
            self.option.pack()
    
            geomstr="%dx%d+0+0" % (w, panel1.winfo_reqheight()+self.option.winfo_reqheight())
            root.geometry(geomstr)
    
    root = tk.Tk()
    root.title('drop down test')
    dropDown(root)
    root.mainloop()
    

    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:

    import Tkinter as tk
    
    class dropDown(tk.Frame):
        def __init__(self, master):
            tk.Frame.__init__(self,master)
    
            #background set_up
            image1 = tk.PhotoImage(file="test.gif")
            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 = tk.StringVar(master)
            self.var.set('Alaska') # initial value
    
            #Have not used countries list just pasted
            self.option = tk.OptionMenu(master, self.var, 'Alaska','Alberta', 'Australia')
            self.option.pack()
    
    
    root = tk.Tk()
    root.title('drop down test')
    d=dropDown(root)
    d.pack(side='top',fill='both',expand='yes')
    root.mainloop()
    

    Note that now Tkinter/TK take care of all the frame resizing for you. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Linux, Python and the Anjuta IDE. I have created a new
I'm fairly new to Python and programming in general. I have done a few
I have long programming background, but am new to Python, and am playing around
I am new to computer programming and have some experience programming with python. I
i have a question because i am fairly new to python, socket programming and
I am new to Python programming... I have a .txt file....... It looks like..
I'm new to python programming. I have this problem: I have a list of
i am new to python programming.is it possible to raise exception in python without
I am quite new in Python programming. While googling I found some of the
I'm pretty new to Python programming and would appreciate some help to a problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.