▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My RU-vid Channel: bit.ly/2UFLKgj bit.ly/2IGzvOR ▶️ See More At: ✅ Join My Facebook Group: Codemy.com bit.ly/2GFmOBz ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt! Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
This is great for putting an image in the new window. Suppose I want to put a plot in the new window? There are many examples on the internet that don't work. Can someone share a piece of working code, that is as simple as this video?
I've been following John's series. It's been great. On this particular video, I noticed that if I kept clicking the "open another window" button, several new windows would open and the images would disappear from the previous windows. Just out of curiosity and know how, I wanted to close the previous window if I opened another window without using the "close button". The way I did it is this (my variable topWindow = John's variable top): 1) add "topWindow = None" to the line above root.mainloop(): topWindow = None root.mainloop() 2) add the follow to just under the first global variable in the open second window def: global topWindow if topWindow is not None: topWindow.destroy()
HI, same 13 year old here, I feel extremely satisfied after watching your tutorials, hope you won't stop making more, I never disliked any of your tutorials
I'm new to coding to tkinter, so my question might sound vague, please bear with me. This video shows basically how to open up a SEPARATE window with the buttons, which makes sense... But what if I wanted to open up a new window layout INSIDE the main window, not as a separate window? Let us say you're at an options menu for a game lobby: When you click on the options menu button, there pops up new buttons for each option category, such as "Game play", "Sound", "Interface", "Network", etc. etc. There's also a button to go back to the previous menu, with it's own set of buttons such as "New game", "Load Game", "Options", "Exit". You wouldn't open up a whole bunch of NEW windows, separate from the main, to get to each menu option. You'd still navigate each selection from within the original window. Otherwise You'd have a whole bunch of messy windows.... So what exactly do I do in order to code a button widget to open up a new layer with menu buttons of it's own, WITHIN the main window, not as a separate window?
You don't want to add a new window for that, you want to add a new frame...then, in that new frame, put whatever new stuff you want. Keep watching the playlist, I discuss frames a lot.
These videos are very helpful in learning Tkinter, I am very thankful for your support too. Want to ask what will the further windows be named like for the second window we used toplevel what for third?
Thanks for the help. I was trying to figure out why none of my variables worked in a second window. It's because if you have more than one Tk() instance, Python gets really confused. If you only do one Tk() and the rest are Toplevel() you won't have this issue.
I don't speak English, I don't understand English, and yet I manage to understand your classes ... isn't it miraculous ? Thank you very much for these courses ;) -> phrase traduite sur Deepl :D
This actually really helped for my assignment in programming, cheers for this!! Question though, can I have two Toplevels working under different defs?
John, I think that declaring the image variable out of the function is a better option than using "global". Because you just load the picture on runtime, and pack it when the function is triggered by the button. Please, correct me if I'm wrong.
@@Codemycom Well... I tried the code below. And it worked... the only difference is that I used just PhotoImage class to load the picture: root = Tk() def open(): toplevel = Toplevel() my_label = Label(toplevel, image=my_img) my_label.pack() my_img = PhotoImage(file= "< 'file path' >") my_button = Button(root, text='Open TopLevel', command=open).pack() root.mainloop()
I've noticed that you can open the same window twice at once using this method, is there a way to make it so you can only open the second window so no more than one at a time can be opened?
Very helpful video! But I do have a query: when I use this open new window function, the treeview that I have specified to show up doesn't have any data in it. It's just an empty treeview. Can anybody help me with this? Thanks!
'top' variable is inside the function and in some cases may not be in scope. This will sometimes result in an error. NameError: name 'top' is not defined. for the function to work correctly, the top variable must be placed before the function definition, and inside the function itself
Awesome tutorial! Would it work with two touch screens? Say like master screen displayed in a 10in touch screen, and slave displayer in a 7in touch screen.
what logic should apply to if " In one window 6 buttons and behind these btns a new window will open " i mean toplevel() is OK or some other logic should apply?
what logic should apply to if " In one window has 6 buttons and behind these btns a new window will open " i mean toplevel() is OK or some other logic should apply?
great tutorials thanks u for helping me learn Tkinter so easily. want to ask that when I close root window, the toplevel window also closes , so how do i stop that?????
Instead of closing the main root window, you can hide it with root.withdraw and bring it back with root.deiconify (put them in buttons or in a function or something that gets called when you create your toplevel window)
HI there, if I click on the "create new window" button more than once, the image will ONLY show on the most recent window, and disappears from the previous window. Could you please explain why this happens and a possible work around to get the image to stay on the screen, despite calling "open" multiple times? Thanks in advance!
# I really dont know why but tried this way and got that working # solution : put the image definition in an array from tkinter import * from PIL import ImageTk,Image img=[] i=0 root=Tk() root.title("Sample window creation") def winopn(): global img,top,lbl1,i top=Toplevel() top.title("Sample second window creation") img.append(ImageTk.PhotoImage(Image.open("d.jpeg")))#instead of d.jpeg you change your image name lbl1=Label(top,image=img[i]).pack() i=i+1 btno=Button(root,text="open the window",command=winopn).pack() root.mainloop() #Well You should put your image name
#I also did this way from tkinter import * from PIL import ImageTk,Image root=Tk() root.title("Sample window creation") openw=1 def winclose(): global openw,top,btnc openw=1 top.destroy() btnc.pack_forget() def winopn(): global openw,img,top,btnc if openw: top=Toplevel() top.title("Sample second window creation") lbl=Label(top,text="hello I am a new window").pack() img=ImageTk.PhotoImage(Image.open("d.jpeg")) lbl1=Label(top,image=img).pack() openw=0 top.protocol("WM_DELETE_WINDOW", winclose) btnc=Button(root,text="Close the window",command=winclose) btnc.pack() btno=Button(root,text="open the window",command=winopn).pack() root.mainloop()
@@Codemycom Yes Indeed should have tried that. Got my answer now. :) Tkinter only accepts .gif files as an image hence we need to import the ImageTk from the PIL Module to let it import other formats.
Sir I am using OOP. with class involved and I want to popup a window from function present inside a class. but when I write it says 'RAM ROM' (class name) object has no attribute Toplevel.Plz help me sir.
You need to designate it to the new window. Make sure your new window is Toplevel() instance, so: new_window = Toplevel() and then make sure your image label references that: my_label = Label(new_window, image=my_img)
i have a question about the syntax highlighting in a tkinter code editor can you please make a video in this topic would be very helpful for various people around the globe.
Hello i have question and i will thank you that help me, I want to create a small program that moves files on my Windows PC from one folder to another, with a simple GUI. How do I do this using python?
Can you tell me how can I acheive on opening second window by closing first window? Example: I click a button on my first window and second window should open with the first window closed. I have tried withdraw() but facing problem of mainloop still being on even if I close second window.
Thanks for the video man,great help for my project. Just a doubt: is it possible to open a text file (about 400 lines : about7000 words) in the new window
@@Codemycom Ohh, I will try again this weekend. Should I define the second top in the first one? I think that's what I did. I would also like to use this opportunity to thank you for all these brilliant videos! They are very informative. I learnt a lot from you. Especially I knew literally nothing abt python but randomly wanted to start learning it someday.
Is there a way when I click open (It opens a new window) the new window opens and is fixed side by side the original window, kind of like a tray? I don't know if I'm explaining what I'm trying to do correctly.
yes, you can set the geometry for each with x,y coordinates. Something like: root.geometry("800x800+100+100") other_windows.geometry("800x800+900+100") or something like that
@@Codemycom Sorry, I worked it out afterwards. The statement "my_img = ImageTk.PhotoImage(Image.open("images/aspen.png")) " simply opens the image but its the label statement below that actually displays the image in the "top" window. So its the label statement doing the work. Thanks, got it!
Please guide me to create a tkinter login system, having mainscreen and subscreen where the username and password is gotten from the user and saved. Then will show invalid if a wrong user inputs details.
Sir jab mai new window me koi normal data insert kar rha hu to wo usi window me insert ho ja rha button pe click karne ke baad. Actually mai usme Python code Krna chahta hun magar mujse ho nhi pa rha. 🙏🙏🙏 Pls sir help me
@@GelsYT No, but do you click a button after selecting an item in a drop down? Because if so it's no different than any button being clicked..you'd just need to run some if/else statements to determine which drop down was selected.
why is the image quality in the tkinter is pretty bad. While displaying an image in the tkinter it looks pretty bad. Any idea how to make everything look beautiful. (i tried ttk),
But if i want to close the first window when the second windows is open, ¿how i do it?, for example, i will do a program with many pages, so, i don't want that always the before windows showed when i created a new it. (Sorry for my english im practicing )
@@Codemycom I have two files (F1.py) and (F2.py), each of which is a window, and I have another file called (main.py) that opens a window with two buttons, I want to click one of the (F1) files every time Or (F2) open. What should I do ?
@@javadmahdavi1151 import the python files into the main file in the normal way and just call them as you would call any new window with tkinter. I have videos on each of those things on the playlist
@@Codemycom When I import all the files in the first code, all my files are opened and executed involuntarily. And also when I import them in a function I get this error. (_ Tkinter.TclError: image "pyimage2" does not exist)
how do I solve this problem? It is coming after a day but before a day this was not coming?: line 13, in my_img1 = ImageTk.PhotoImage(Image.open("images/de2.gif")) AttributeError: type object 'Image' has no attribute 'open'
@@Codemycom I just saw this video ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-H_zZiIlnB8M.html and I don't want to limit at 1. I would like the counter to decrease after the window is closed, so window can be opened and closed many times. It is possible? Thank you!
I have a problem, I want to use two pictures, first for main and second for second window, so, in first window everything is ok, when I run it, but...if I run another window, first window lost wallpaper, why? How to fix?
@@Codemycom sir i did it and it said TopLevel() not defined so I tried "Tk()" and it worked lol.. anyways sir you are my inspiration to code tkinter thanks very much may you get a billion subs
from tkinter import * from tkinter.ttk import* def play(): top = Toplevel() top.title("Riddle me this") top.geometry("500x500") Label(top,text ="1. Riddle: What starts with ‘e,' ends with ‘e,' and contains one letter?").pack() Label(top,text ="Type your guess, or type 'hint' or give up' in cmd.").pack() entry1 = Entry(top, text ="").pack() guess = entry1.get() b1 = Button(top, text="Submit").pack() print(guess) root = Tk() root.title("asdasd") app = Frame(root) app.grid() playb = Button(app, text = "Play", command = play) playb.grid() root.mainloop() here's my code