Python Forum

Full Version: Make A Button That Opens Another Tk() Window That I Have Made
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have made two windows
StartScreen=tk()
and FirstScreen=tk()
I want to make a button on StartScreen that opens up the window FirstScreen
This is the code for the startscreen-
###################################################
from tkinter import *
##################################################
StartScreen=Tk()
##Photo Car##
PhotoCarRed = PhotoImage(file="D:\Python Projects\Parking Management System\Photos\Best-High-Resolution-Photos-For-Cars.png")
PlacementPhotoCarRed = Label(StartScreen, image = PhotoCarRed)
PlacementPhotoCarRed.pack(side="top", fill=X )
###ToolBar on the bottom of the screen
toolbar= Frame(StartScreen, bg="white")
Button1 = Button(toolbar, text="Book A Parking Space Right Now!", relief = RAISED)
Button1.pack(side="left", padx=10, pady=10)
Button2 = Button(toolbar, text="Have Your Own Parking? Register With Us!", relief = RAISED)
Button2.pack(side="left", padx=10, pady=10)
Button3 = Button(toolbar, text="Want To Cancel Your Reservation?", relief = RAISED)
Button3.pack(side="right", padx=10, pady=10)
toolbar.pack(side="bottom")

StartScreen.mainloop()
This is the code for the second tk() that is FirstScreen

####################
from tkinter import *
####################
FirstScreen = Tk()
###################
"""Size of city screen image = 720x200 px"""
WelcomePic = PhotoImage(file="D:\Python Projects\Parking Management System\Photos\CITYWALLPAPERLOWERTOOLBAR.png")
WelcomePicPlacement=Label(FirstScreen,image=WelcomePic)
WelcomePicPlacement.pack(side="top",fill="both")
######################
"""Drop Drop Menus On The Top Of The Screen"""
#######################
DropDownMenuToShowcase = Menu(FirstScreen)
FirstScreen.configure(menu=DropDownMenuToShowcase)

WhatWeDo= Menu(DropDownMenuToShowcase)
DropDownMenuToShowcase.add_cascade(label="What We Do", menu = WhatWeDo)
WhatWeDo.add_command(label="Reservations For Hotel Parking")
WhatWeDo.add_command(label="Reservations For Clubs")
WhatWeDo.add_command(label="Reservations For Events")
WhatWeDo.add_command(label="Reservations For Institutions ")
WhatWeDo.add_command(label="Reservations For Workplaces")

FirstScreen.mainloop()
I want to make a button on StarScreen, which, upon clicking, makes the FirstScreen window appear.

Thank you.
Dont create 2 root windows, create one root window and a toplevel
http://effbot.org/tkinterbook/toplevel.htm
I made a function and assigned it to a button
The function goes like

def YesWe():
FirstScreen=Toplevel(StartScreen)

Do I have to place all my code for how I want FirstScreen to look like inside this function because this reads as a local variable.
Hey there, Im literally just getting into tkinter wouldn't logic dictate to just use callback functions from the StartScreen to the FirstScreen on x button? All in one script... and yeah like Saif said, not reason to have both as root level. I'm unclear to what you are trying to say ...

(Jan-05-2017, 02:16 AM)Saif133 Wrote: [ -> ]def YesWe():
FirstScreen=Toplevel(StartScreen)

Could you should the entire Script please? Thank you.

ps: Look up pygubu-designer! Its helping me enormously, but the need to understand windows build structure is needed.
Quote:and yeah like Saif said, not reason to have both as root level.

Just to clarify, There is a reason to not have both at root level, it's not legal to do so, you must use Toplevel. If you wish
to hide the root window, use withdraw.
Well the way he h
(Jan-20-2017, 07:44 PM)Larz60+ Wrote: [ -> ]Just to clarify, There is a reason to not have both at root level, it's not legal to do so, you must use Toplevel. If you wish
to hide the root window, use withdraw.
Well Hes issuing two different scripts (from what it looks like at least) which in theory yeah... you could have one script call an other but can streamline the thing into one is best... Were saying the same thing Larz ! lol I just try to use flowery language by to not come off as smart-Alec.