▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My TH-cam 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?
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.
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()
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.
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?
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
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()
'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
This actually really helped for my assignment in programming, cheers for this!! Question though, can I have two Toplevels working under different defs?
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!
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.
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?
i've found one tape this just after "def open(): " global top if 'top' in globals() and top.winfo_exists(): # Check if top already exists top.lift() # Bring it to the front if it exists return # Exit if it's already open
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)
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?
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.
@@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.
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
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.
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?
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()
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
@@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.
@@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!
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.
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.
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)
@@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)
@@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.
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
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 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
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 I just saw this video th-cam.com/video/H_zZiIlnB8M/w-d-xo.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!
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),
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)
▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My TH-cam 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?
At this point, I think I should pause my life and watch all your videos before I continue. It'll really save me a lot of stress and time.
haha nice
I'm currently doing just that lol
Im on 2 weeks sick leave and im bingewhatching all of theese videos :D
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
Great to hear!
3 days I've spent on this and you solved it in a couple of mins. Can't thank you enough.
Awesome, glad you found it!
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.
Codemy.com thanks!
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()
thanks, I was thinking in that problem while working in my project, now I do not have to get headache trying to solve it.
Your videos are the best on TH-cam.
professional, clear, smart, easy to understand ... etc
Wow, thanks!
You're welcome!
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.
Yep...you can use global variables too, to get around that...
idk what I'd do without you
Glad you're enjoying the videos :-)
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?
you can use toplevel again, just give it another variable name...or you can name them anything you want
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
You're welcome 😊
So you used Google translate to write this comment??
@@sumedhasharma1984 yes, I'm sorry but my english level is very low :(
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.
You're wrong. Tkinter's garbage function does a thing if you don't use global.
@@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()
And again, you spared me a lot more sleepless nights trying to figure out this struggle. Thanks, Codemy :-)
Happy to help!
Its freaky friday here in vegas. Your vids are great man
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
Cannot express how grateful I am to you. Thanks!!
Thanks! Glad you're enjoying the videos!
I so much enjoy your tutorials.... 👌🏾👍🏾
Glad to hear it!
This actually really helped for my assignment in programming, cheers for this!!
Question though, can I have two Toplevels working under different defs?
sure, just call them different things..that's how you open a second window for instance
codemy.com you are awesome . This video helped me a lot. Thanks
Glad it helped!
This is master class material! Thank you Codemy :)
You're very welcome!
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!
THAT GLOBAL THING - Thank you!
Thank you for the video! How do I add a frame to a Toplevel() window? I can't seem to find an answer anywhere.
Thanks for your help,they help me a lot!
Good for you !! Thanks for the video, helped me!
Glad it helped!
I'm losing my mind why the image is not appearing in my second window. You're really a great help thanks!!
Happy to hear it!
Buen video.
Una consulta cuantos def puedo anidar dentro de un def
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.
No idea...but I don't see why not
Thanks! great video.
cool... got one working already, Thanks John.How do you bring the 2nd window back. Destroy command seems to do just that !!!
Glad to hear!
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?
i've found one tape this just after "def open(): "
global top
if 'top' in globals() and top.winfo_exists(): # Check if top already exists
top.lift() # Bring it to the front if it exists
return # Exit if it's already open
just what i needed thanks
Nice!
Thanks a lot, this is what I was searching
Glad you found it then!
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)
please kindly explain how to create second window inside the first main window, just like MDIForm in Visual Basic.
thank you so much for this video. Very clear to understand
sure thing
The video was very helpful....can u also pls tell how to close the root window and not the second window
Think I talk about that in the playlist somewhere...
@@Codemycom I actually looked for it but couldn't find it....could u tell me which video particularly if possible
@@varman8048 Sorry, you'll have to dig thru them
@@Codemycom ok, Sir...Thanks
Hello John Sir .
But what If we wants to create the third window from the 2nd window tkinter window !
How can we do that ??
In the same way
Can you show how to insert values into a database in a second window please
Same as doing it in the first window.
Sir, can a variable or a widget in Toplevel be accessed in the main window ?
It depends. Try making the variable global
yes obviously
Super useful video - thanks!
Thanks for watching!
Overall amzing tutorials
Thanks
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?
can you plz help with how first window get close when 2nd opens
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.
Sorry, I don't understand what you mean by 'syntax highlighting in a tkinter code editor'
@@Codemycom I think what he's asking about is your IDE and its colorization.
@@alexsteinkamp9431 I just use the default Sublime Text.
Do we need to import ImageTk ?? Won't PhotoImage alone be sufficient enough to load the image ??
Try it without and see
@@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.
thank you ,teacher
You're very welcome
Hi, thank you very much for your video.
Sir, what's is the difference between root.quit & root.destroy? Just wanted to know.
For all intents and purposes...not much :-p
i thought uou would make it:
for i in 255:
print('Create New Windows in Tkinter - Python Tkinter GUI Tutorial #' + str(i))
Please make qt designer series
I don't know qt designer
Great job sir! Thank you sir
You are welcome
why cant I open images? i tried r"...." as raw string. I also tried \\ double backshlshes instead of normal ones. Nothing doesnt work.
Help me pls
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
Sure...why not? Check the playlist towards the end, I'm building a text editor where we open text files.
@@Codemycom k man thx , you have been a great help
@@asimjasim6103 Happy to help :-)
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.
Using top.mainloop() within the function also displays the image without the use of global variable.WHY?
That's just how they built it to work
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?
I wonder if you could use command line for that and have python execute the command line.
@@P_Rodd
hello
thanks for ur answer but i dont know what u means
plz help me more
Hello John,
How to hide the main root window when the top window is open or get back the root window when top window is destroyed?
I have videos on that in the playlist
How Can I do an InternalTopLevel in Python like as JInternalFrame in Java
I don't know java
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()
What if we use .quit instead of using destroy..?
How to create a third window..?
ofc a udemy ad is required before the video starts
Yeah, that's how youtube works.
Best playlist
Thanks!
@@Codemycom How can i make my player (if he opt being 'Tiger' ) appear to a position on my grid where i mouse click
@@sakshiharbhajanka2481 USe binding...I have videos on that.
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
What will happen if top is assigned as Tk()
I have a doubt whether toplevel () which is assigned to top is a keyword...?
Give it a try and see
I tried to make a third window with the same method but failed. I guess it will require other codes to build a third window on top of the second one?
no other code needed, you just did something incorrectly.
@@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.
How is it that the image 'my_img' is not associated with a window?? Is there some default here?
Sorry, I'm not sure what you're asking. You did associate it with a window, when you listed it as root.
@@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!
Why not using a class where you fix ImageTk as self.ImageTk ?
Why bother?
Sir I want to know how to import another window in python where I can add new labels entry text field
Sorry, I don't know what that means
which version of python are you using?
The latest version...it doesn't matter.
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.
I have a video about this further down the tkinter playlist. Check it out.
@@Codemycom Okay I will check that!
Thanks
@@davejenil1537 Sure thing
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.
You can learn everything you need to do that by watching the videos of this playlist.
The image I want to display in the second window is being displayed over the first window. What should I do?
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)
@@Codemycom thx man this saved me a lot of time
@@WalterWhite-dr2yz You mean it actually worked? lol ;-)
Ya dude ur great 👍
@@WalterWhite-dr2yz ha thanks
Instead of making the image global I create my_img outside the function and then create the label/pack it in the function. Any reason not to do this?
Try it and see.
@@Codemycom So far so good. I guess time will tell if I run into issues as the program grows.
How can one add a figure in the new window? I am having trouble and there is a lot of non-working examples on the internet
in the same way you put them in the main window...instead of root, use the name of the window
@@Codemycom Thanks very much. It is implicit in what you covered, but now I get it.
Hi, I have two files x2_ui.py and x1_ui.py that I want to open in a file as a window. How should I do this?
Without knowing what those files are, I couldn’t possibly say
@@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 Thank's for your help
can you give me a link of title of that video?
@@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)
Do you know the reason why .pack() and .grid() cannot be present in a single window
They can be, but just not in the same parent. So if you pack a frame onto a window...inside the frame you can grid etc.
@@Codemycom thanks !!!
@@procode6881 sure thing
Are you in Vegas?
Yes
@@Codemycom 😂 loving the tkinter playlist so far. These are just the kind of tutorials I was looking for. Thanks
@@ninjatribble7961 Awesome, glad you like em!
whats the difference between . .quit and .destroy???
for all intents and purposes...not much
Thank you =)
You're very welcome!
@@Codemycom I love your tutorials man! =) you explain and do it in the simplest waaaaaay and that is what most of us need
@@GelsYT Glad you're enjoying them!
@@Codemycom Hello again! may I ask if you have a tutorial on how to display new window is an item is clicked from a dropdown? thank you
@@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.
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
You are a stand up guy thank you so much!!!
@@JFizzzzzzzz sure thing!
Sir, i created a button on clicking opens window1 but it creates window2,3,4.... on every click i want to limit that only one window.
Any solution.
Disable the button after one click...
myButton['state'] = DISABLED
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'
maybe it can't handle .gif's....did you import Image at the top of your file? Spell it with a capital I?
@@Codemycom i have done it still it doesn't work??
it shows that the image has no attribute 'open'
@@Codemycom yesterday it was working nicely but now it just stopped???
it is showing that 'ATTRIBUTE ERROR'????
@@parul0601 yes, I know all that already. You can't use .gif images. Try a png or jpg
is it possible to instead of just opening a second window also close the first, so that the second window is all that remains on screen?
yes
@@Codemycom what should I google to be able to see how it'd done?
@@nicolasrosso3800 Check the playlist, pretty sure I did a video on it
You can do it by Tk() also I tried u do not need to do it by Toplevel()
Yes you can, but you'll run into problems doing it that way.
@@Codemycom can you please tell me the errors that i can get
@@aryamannatrajan4850 No. Why not just do it the way you're supposed to.
How to set toplevel image as background image
make your image variable global
how to open another window inside a toplevel()?
pls reply
just name it like before
@@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
can't I use Tk() instead of Toplevel() ?
Edit:whats the main difference
No, you already use Tk()
sir how can we close the existing window and then open a new window with a button.
Check the playlist, I go over that
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?
Without seeing your code, I couldn't guess...
@@Codemycom give mi 3min, I'll give you link
@@Codemycom files.fm/u/r2dea99z
Ok it was 23min xD Was trying to fix, but nothing
@@Codemycom How code should look if I want background, like on window behind it?
@@deki90to check my tkinter playlist, I have videos on images
button on root screen will open second window multiple times, how can i prevent to opn window, if it is already opened once
Use a counter and if statement
Hello. Did you succeed with a counter? Me no :(
@@Codemycom I just saw this video th-cam.com/video/H_zZiIlnB8M/w-d-xo.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!
@@lucianmardale10 sure, why not...just change the counter
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),
It looks fine to me...not bad at all.
why I can't use from tkinder import * it showing error at from that is unused import(s)
you misspelled tkinter
@@Codemycom sorry but while typing I used correct spelling of tkinter, did I need to install all imports like Button, Label,Tk....
note: typing in VS Code not in this comment
@@fastandfurious2171 I would never use VS Code for tkinter. I have no idea how you need to setup VS Code for tkinter
Sir can you please make a vidieo on how to play GIF in tkinter window.
PLEASE SIR, I request
No, sorry. There's no easy way to do that in Tkinter.
Sir, then how can i play loading scenes in tkinter?
Please help me sir
@@rithiksaran This video shows you how to create new windows.
No sir, How can i create a loading screen? Please teach me sir
6:45 why img didn't load, due to scope
I want to create a new window for my TextEditor And I just want to duplicate my Default window
go for it
I got this error: NameError: name 'Toplevel' is not defined
Check your code for typos
can you help me the submit button does not exit on my new window :(
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
you you using IDLE?
Yes sir
how can open new window in the same root window
you don't open windows inside windows....they are definitionally outside each other.