0

I'm creating a splash screen that will be the introduction to my program. I have managed to place an image on the screen but as soon as I add a button nothing comes up, not even the tkinter window.

What I'm trying to do is have an image on the top of the window, under it a text box with my name "Bob Johns" then another button that says "Enter", which will take the user to another section of the program (i.e. start the application). All of this aligned to the centre.

Here's what I have so far:

from Tkinter import *
from PIL import ImageTk, Image
import os

#create the window
root = Tk()

#modify root window
root.title("Labeler")
root.geometry("500x500")#Width x Height

img = ImageTk.PhotoImage(Image.open("test.gif"))
panel = Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")

#If i add this section the program goes awol--------------
app = Frame(root)
app.grid()
button1 = Button(app, text = "This is a button")
button1.grid()
#---------------------------------------------------------


#Start the event loop
root.mainloop()
user3423572
  • 559
  • 1
  • 7
  • 21

1 Answers1

2

The code is mixing pack and grid.

Use only one layout manager at once (at least for the widgets who share same parent)

...
img = ImageTk.PhotoImage(Image.open("test.gif"))
panel = Label(root, image = img)
panel.pack(side="top", fill = "both", expand = "yes")

app = Frame(root)
app.pack(side='bottom')
button1 = Button(app, text = "This is a button")
button1.pack()
...
falsetru
  • 357,413
  • 63
  • 732
  • 636
  • Thank you! Worked like a charm. Just tried to add text using - master = Tk() w = Label(master, text="Hello, world!") w.pack() but it creates a new tkinter window, how do i place it within the same one? (p.s. cant get the code thiing to work) – user3423572 Oct 12 '14 at 13:56
  • @user3423572, Please post it as a separate question. – falsetru Oct 12 '14 at 13:57
  • That was part of my original question but okay – user3423572 Oct 12 '14 at 13:59
  • @user3423572, In short, instead of making another `Tk` object, reuse the old `Tk` object. (See [this answer](http://stackoverflow.com/a/15995920/2225682) to know how to remove widgets) – falsetru Oct 12 '14 at 14:03
  • @user3423572, Search for `tkinter splash` will give you hint. – falsetru Oct 12 '14 at 14:04
  • I tried the topic you linked but all i managed to do was delete the button and the text was still on another window. I'll post a new question as I now have another issue. Thanks for the help – user3423572 Oct 12 '14 at 14:50
  • @user3423572, I made a simple script based on your code. I wish it help you understand what I meant in the previous comment.: http://pastebin.com/BmXuRtKS – falsetru Oct 12 '14 at 14:55
  • Thank you ever so much, that helped me out a ton. I managed to expand the code you sent and add textboxes, drop down menus and plaintext within the same window. Just got some formatting issues but I can sort that another time. Thanks once again! – user3423572 Oct 12 '14 at 15:20