Python Forum
[Tkinter] Make A Button That Opens Another Tk() Window That I Have Made
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Make A Button That Opens Another Tk() Window That I Have Made
#1
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.
Reply
#2
Dont create 2 root windows, create one root window and a toplevel
http://effbot.org/tkinterbook/toplevel.htm
Recommended Tutorials:
Reply
#3
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.
Reply
#4
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.
Reply
#5
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.
Reply
#6
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 341 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  How can I run an interface I made using PyQt5 and a Map program I made using Tkinter bki 6 1,035 Nov-09-2023, 11:12 PM
Last Post: bki
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,369 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] how to make label or button not visible with the place method? nowayj63 2 2,632 Jan-03-2023, 06:29 PM
Last Post: Yoriz
Question [Tkinter] How to make split button? teknixstuff 2 1,017 Jan-03-2023, 06:21 PM
Last Post: Yoriz
  [Tkinter] MenuBar hidden when new window opens john8888 5 1,357 Sep-14-2022, 02:32 PM
Last Post: john8888
  [Tkinter] GUI Opens Minimized gw1500se 24 5,525 May-05-2022, 04:12 PM
Last Post: deanhystad
  [Tkinter] Clicking on the button crashes the TK window ODOshmockenberg 1 2,196 Mar-10-2022, 05:18 PM
Last Post: deanhystad
  [Tkinter] Make my button text update? Skata100 1 2,012 Aug-07-2021, 05:37 AM
Last Post: deanhystad
  [Tkinter] [split] [split] How to make a window stay on top knoxvilles_joker 10 6,032 May-22-2021, 03:54 AM
Last Post: knoxvilles_joker

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020