Create New Windows in tKinter - Python Tkinter GUI Tutorial #14

  Рет қаралды 164,416

Codemy.com

Codemy.com

Күн бұрын

Пікірлер: 285
@Codemycom
@Codemycom 4 жыл бұрын
▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My KZbin 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
@prbprb2
@prbprb2 3 жыл бұрын
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?
@mikem8915
@mikem8915 5 жыл бұрын
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()
@adonisnunez6078
@adonisnunez6078 Жыл бұрын
thanks, I was thinking in that problem while working in my project, now I do not have to get headache trying to solve it.
@kennethobeng9127
@kennethobeng9127 3 жыл бұрын
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.
@Codemycom
@Codemycom 3 жыл бұрын
haha nice
@JadeJuno
@JadeJuno 3 жыл бұрын
I'm currently doing just that lol
@janpaweii3115
@janpaweii3115 2 жыл бұрын
Im on 2 weeks sick leave and im bingewhatching all of theese videos :D
@sarthaksrivastava6282
@sarthaksrivastava6282 4 жыл бұрын
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?
@Codemycom
@Codemycom 4 жыл бұрын
you can use toplevel again, just give it another variable name...or you can name them anything you want
@campanion
@campanion 4 жыл бұрын
idk what I'd do without you
@Codemycom
@Codemycom 4 жыл бұрын
Glad you're enjoying the videos :-)
@milanspanko241
@milanspanko241 2 жыл бұрын
And again, you spared me a lot more sleepless nights trying to figure out this struggle. Thanks, Codemy :-)
@Codemycom
@Codemycom 2 жыл бұрын
Happy to help!
@-kerplink-7738
@-kerplink-7738 3 жыл бұрын
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?
@TheKen82815
@TheKen82815 2 жыл бұрын
Cannot express how grateful I am to you. Thanks!!
@Codemycom
@Codemycom 2 жыл бұрын
Thanks! Glad you're enjoying the videos!
@creativecore3575
@creativecore3575 3 жыл бұрын
This is master class material! Thank you Codemy :)
@Codemycom
@Codemycom 3 жыл бұрын
You're very welcome!
@victornunes5888
@victornunes5888 2 жыл бұрын
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
@Codemycom 2 жыл бұрын
You're wrong. Tkinter's garbage function does a thing if you don't use global.
@victornunes5888
@victornunes5888 2 жыл бұрын
@@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()
@circuit6896
@circuit6896 4 жыл бұрын
This actually really helped for my assignment in programming, cheers for this!! Question though, can I have two Toplevels working under different defs?
@Codemycom
@Codemycom 4 жыл бұрын
sure, just call them different things..that's how you open a second window for instance
@reginajalandoni3524
@reginajalandoni3524 Жыл бұрын
I'm losing my mind why the image is not appearing in my second window. You're really a great help thanks!!
@Codemycom
@Codemycom Жыл бұрын
Happy to hear it!
@stivunnikolov5941
@stivunnikolov5941 3 жыл бұрын
Its freaky friday here in vegas. Your vids are great man
@Codemycom
@Codemycom 3 жыл бұрын
Thanks!
@procode6881
@procode6881 4 жыл бұрын
Thanks for your help,they help me a lot!
@funnyclips2696
@funnyclips2696 2 жыл бұрын
I so much enjoy your tutorials.... 👌🏾👍🏾
@Codemycom
@Codemycom 2 жыл бұрын
Glad to hear it!
@flyingdinosaur8871
@flyingdinosaur8871 2 жыл бұрын
THAT GLOBAL THING - Thank you!
@gauravpatell
@gauravpatell 4 жыл бұрын
codemy.com you are awesome . This video helped me a lot. Thanks
@Codemycom
@Codemycom 4 жыл бұрын
Glad it helped!
@paulwatterson5992
@paulwatterson5992 2 жыл бұрын
Thanks! great video.
@devve7
@devve7 3 жыл бұрын
Good for you !! Thanks for the video, helped me!
@Codemycom
@Codemycom 3 жыл бұрын
Glad it helped!
@amankumarbairagi794
@amankumarbairagi794 4 жыл бұрын
Hello John Sir . But what If we wants to create the third window from the 2nd window tkinter window ! How can we do that ??
@Codemycom
@Codemycom 4 жыл бұрын
In the same way
@joseluisvelasquezrodriguez5143
@joseluisvelasquezrodriguez5143 4 жыл бұрын
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.
@Codemycom
@Codemycom 4 жыл бұрын
No idea...but I don't see why not
@skmplanet9591
@skmplanet9591 4 жыл бұрын
Thanks a lot, this is what I was searching
@Codemycom
@Codemycom 4 жыл бұрын
Glad you found it then!
@mister6497
@mister6497 Жыл бұрын
i thought uou would make it: for i in 255: print('Create New Windows in Tkinter - Python Tkinter GUI Tutorial #' + str(i))
@445gautam
@445gautam 3 жыл бұрын
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.
@raniduharshana5238
@raniduharshana5238 4 жыл бұрын
thank you so much for this video. Very clear to understand
@Codemycom
@Codemycom 4 жыл бұрын
sure thing
@abdullahtariq95don
@abdullahtariq95don 3 жыл бұрын
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?
@abdullahtariq95don
@abdullahtariq95don 3 жыл бұрын
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?
@pverprogramz641
@pverprogramz641 4 жыл бұрын
Sir, can a variable or a widget in Toplevel be accessed in the main window ?
@Codemycom
@Codemycom 4 жыл бұрын
It depends. Try making the variable global
@Surferdudeoh
@Surferdudeoh 3 жыл бұрын
yes obviously
@juanbernal5641
@juanbernal5641 3 жыл бұрын
Buen video. Una consulta cuantos def puedo anidar dentro de un def
@andrewhadfield7754
@andrewhadfield7754 4 жыл бұрын
Super useful video - thanks!
@Codemycom
@Codemycom 4 жыл бұрын
Thanks for watching!
@parsabahrambeik4381
@parsabahrambeik4381 4 жыл бұрын
Hi, thank you very much for your video.
@yuxuyang3196
@yuxuyang3196 Ай бұрын
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?
@Codemycom
@Codemycom Ай бұрын
no other code needed, you just did something incorrectly.
@yuxuyang3196
@yuxuyang3196 Ай бұрын
@@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.
@c0dingwithchris
@c0dingwithchris 4 жыл бұрын
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!
@bheriraju722
@bheriraju722 3 жыл бұрын
# 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
@bheriraju722
@bheriraju722 3 жыл бұрын
#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()
@mee8963
@mee8963 3 жыл бұрын
What if we use .quit instead of using destroy..? How to create a third window..?
@hellobro8837
@hellobro8837 3 жыл бұрын
Sir, what's is the difference between root.quit & root.destroy? Just wanted to know.
@Codemycom
@Codemycom 3 жыл бұрын
For all intents and purposes...not much :-p
@pranavguptaa
@pranavguptaa 4 жыл бұрын
Using top.mainloop() within the function also displays the image without the use of global variable.WHY?
@Codemycom
@Codemycom 4 жыл бұрын
That's just how they built it to work
@mee8963
@mee8963 3 жыл бұрын
What will happen if top is assigned as Tk() I have a doubt whether toplevel () which is assigned to top is a keyword...?
@Codemycom
@Codemycom 3 жыл бұрын
Give it a try and see
@ะ้ฟืฟแ้นะพพําพําพําพํา
@ะ้ฟืฟแ้นะพพําพําพําพํา 4 жыл бұрын
thank you ,teacher
@Codemycom
@Codemycom 4 жыл бұрын
You're very welcome
@adityarathi4312
@adityarathi4312 4 жыл бұрын
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?
@Codemycom
@Codemycom 4 жыл бұрын
I have videos on that in the playlist
@34__priyadharshini.r62
@34__priyadharshini.r62 4 жыл бұрын
Great job sir! Thank you sir
@Codemycom
@Codemycom 4 жыл бұрын
You are welcome
@varman8048
@varman8048 4 жыл бұрын
The video was very helpful....can u also pls tell how to close the root window and not the second window
@Codemycom
@Codemycom 4 жыл бұрын
Think I talk about that in the playlist somewhere...
@varman8048
@varman8048 4 жыл бұрын
@@Codemycom I actually looked for it but couldn't find it....could u tell me which video particularly if possible
@Codemycom
@Codemycom 4 жыл бұрын
@@varman8048 Sorry, you'll have to dig thru them
@varman8048
@varman8048 4 жыл бұрын
@@Codemycom ok, Sir...Thanks
@bhushanwagh7192
@bhushanwagh7192 4 жыл бұрын
Please make qt designer series
@Codemycom
@Codemycom 4 жыл бұрын
I don't know qt designer
@jenishshrestha8613
@jenishshrestha8613 3 жыл бұрын
whats the difference between . .quit and .destroy???
@Codemycom
@Codemycom 3 жыл бұрын
for all intents and purposes...not much
@infogera1
@infogera1 2 жыл бұрын
How Can I do an InternalTopLevel in Python like as JInternalFrame in Java
@Codemycom
@Codemycom 2 жыл бұрын
I don't know java
@davejenil1537
@davejenil1537 4 жыл бұрын
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.
@Codemycom
@Codemycom 4 жыл бұрын
I have a video about this further down the tkinter playlist. Check it out.
@davejenil1537
@davejenil1537 4 жыл бұрын
@@Codemycom Okay I will check that! Thanks
@Codemycom
@Codemycom 4 жыл бұрын
@@davejenil1537 Sure thing
@parul0601
@parul0601 4 жыл бұрын
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
@Codemycom 4 жыл бұрын
maybe it can't handle .gif's....did you import Image at the top of your file? Spell it with a capital I?
@parul0601
@parul0601 4 жыл бұрын
@@Codemycom i have done it still it doesn't work??
@parul0601
@parul0601 4 жыл бұрын
it shows that the image has no attribute 'open'
@parul0601
@parul0601 4 жыл бұрын
@@Codemycom yesterday it was working nicely but now it just stopped??? it is showing that 'ATTRIBUTE ERROR'????
@Codemycom
@Codemycom 4 жыл бұрын
@@parul0601 yes, I know all that already. You can't use .gif images. Try a png or jpg
@Integrate2
@Integrate2 Жыл бұрын
File "", line 2, in ImportError: cannot import name 'ImageTK' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)
@javadmahdavi1151
@javadmahdavi1151 3 жыл бұрын
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?
@Codemycom
@Codemycom 3 жыл бұрын
Without knowing what those files are, I couldn’t possibly say
@javadmahdavi1151
@javadmahdavi1151 3 жыл бұрын
@@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 ?
@Codemycom
@Codemycom 3 жыл бұрын
@@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
@javadmahdavi1151
@javadmahdavi1151 3 жыл бұрын
@@Codemycom Thank's for your help can you give me a link of title of that video?
@javadmahdavi1151
@javadmahdavi1151 3 жыл бұрын
@@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)
@sakshiharbhajanka2481
@sakshiharbhajanka2481 3 жыл бұрын
Best playlist
@Codemycom
@Codemycom 3 жыл бұрын
Thanks!
@sakshiharbhajanka2481
@sakshiharbhajanka2481 3 жыл бұрын
@@Codemycom How can i make my player (if he opt being 'Tiger' ) appear to a position on my grid where i mouse click
@Codemycom
@Codemycom 3 жыл бұрын
@@sakshiharbhajanka2481 USe binding...I have videos on that.
@JFizzzzzzzz
@JFizzzzzzzz 4 жыл бұрын
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.
@Codemycom
@Codemycom 4 жыл бұрын
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
@JFizzzzzzzz
@JFizzzzzzzz 4 жыл бұрын
You are a stand up guy thank you so much!!!
@Codemycom
@Codemycom 4 жыл бұрын
@@JFizzzzzzzz sure thing!
@nicolasrosso3800
@nicolasrosso3800 4 жыл бұрын
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?
@Codemycom
@Codemycom 4 жыл бұрын
yes
@nicolasrosso3800
@nicolasrosso3800 4 жыл бұрын
@@Codemycom what should I google to be able to see how it'd done?
@Codemycom
@Codemycom 4 жыл бұрын
@@nicolasrosso3800 Check the playlist, pretty sure I did a video on it
@procode6881
@procode6881 4 жыл бұрын
Do you know the reason why .pack() and .grid() cannot be present in a single window
@Codemycom
@Codemycom 4 жыл бұрын
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.
@procode6881
@procode6881 4 жыл бұрын
@@Codemycom thanks !!!
@Codemycom
@Codemycom 4 жыл бұрын
@@procode6881 sure thing
@shubhanshusharma5372
@shubhanshusharma5372 3 жыл бұрын
How to set toplevel image as background image
@Codemycom
@Codemycom 3 жыл бұрын
make your image variable global
@krishnakotni9231
@krishnakotni9231 4 жыл бұрын
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),
@Codemycom
@Codemycom 4 жыл бұрын
It looks fine to me...not bad at all.
@Momo-bb2fn
@Momo-bb2fn 3 жыл бұрын
6:45 why img didn't load, due to scope
@shaunakn5881
@shaunakn5881 4 жыл бұрын
how to open another window inside a toplevel()? pls reply
@Codemycom
@Codemycom 4 жыл бұрын
just name it like before
@shaunakn5881
@shaunakn5881 4 жыл бұрын
@@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
@sanjayrajasreeraja3456
@sanjayrajasreeraja3456 4 жыл бұрын
sir how can we close the existing window and then open a new window with a button.
@Codemycom
@Codemycom 4 жыл бұрын
Check the playlist, I go over that
@evinlerrickmosca4853
@evinlerrickmosca4853 3 жыл бұрын
can you help me the submit button does not exit on my new window :(
@evinlerrickmosca4853
@evinlerrickmosca4853 3 жыл бұрын
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
@Codemycom
@Codemycom 3 жыл бұрын
you you using IDLE?
@evinlerrickmosca4853
@evinlerrickmosca4853 3 жыл бұрын
Yes sir
@GelsYT
@GelsYT 4 жыл бұрын
Thank you =)
@Codemycom
@Codemycom 4 жыл бұрын
You're very welcome!
@GelsYT
@GelsYT 4 жыл бұрын
@@Codemycom I love your tutorials man! =) you explain and do it in the simplest waaaaaay and that is what most of us need
@Codemycom
@Codemycom 4 жыл бұрын
@@GelsYT Glad you're enjoying them!
@GelsYT
@GelsYT 4 жыл бұрын
@@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
@Codemycom
@Codemycom 4 жыл бұрын
@@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.
@juanpaperez100
@juanpaperez100 5 жыл бұрын
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
@Codemycom 5 жыл бұрын
Great Question! use root.withdraw() to hide our main root window, and root.deiconify() to bring it back.
@MedTech1
@MedTech1 3 жыл бұрын
I want to create a new window for my TextEditor And I just want to duplicate my Default window
@Codemycom
@Codemycom 3 жыл бұрын
go for it
@aryamannatrajan4850
@aryamannatrajan4850 4 жыл бұрын
You can do it by Tk() also I tried u do not need to do it by Toplevel()
@Codemycom
@Codemycom 4 жыл бұрын
Yes you can, but you'll run into problems doing it that way.
@aryamannatrajan4850
@aryamannatrajan4850 4 жыл бұрын
@@Codemycom can you please tell me the errors that i can get
@Codemycom
@Codemycom 4 жыл бұрын
@@aryamannatrajan4850 No. Why not just do it the way you're supposed to.
@mohammadsorour1
@mohammadsorour1 3 жыл бұрын
how can open new window in the same root window
@Codemycom
@Codemycom 3 жыл бұрын
you don't open windows inside windows....they are definitionally outside each other.
@dr.strawberry7612
@dr.strawberry7612 4 жыл бұрын
I tried this trick but when I did it it said top was not defined! PLEASE HELP!!!
@Codemycom
@Codemycom 4 жыл бұрын
Rewatch the video and check your code for errors.
@rithiksaran
@rithiksaran Жыл бұрын
Sir can you please make a vidieo on how to play GIF in tkinter window. PLEASE SIR, I request
@Codemycom
@Codemycom Жыл бұрын
No, sorry. There's no easy way to do that in Tkinter.
@rithiksaran
@rithiksaran Жыл бұрын
Sir, then how can i play loading scenes in tkinter?
@rithiksaran
@rithiksaran Жыл бұрын
Please help me sir
@Codemycom
@Codemycom Жыл бұрын
@@rithiksaran This video shows you how to create new windows.
@rithiksaran
@rithiksaran Жыл бұрын
No sir, How can i create a loading screen? Please teach me sir
@ninjatribble7961
@ninjatribble7961 4 жыл бұрын
Are you in Vegas?
@Codemycom
@Codemycom 4 жыл бұрын
Yes
@ninjatribble7961
@ninjatribble7961 4 жыл бұрын
@@Codemycom 😂 loving the tkinter playlist so far. These are just the kind of tutorials I was looking for. Thanks
@Codemycom
@Codemycom 4 жыл бұрын
@@ninjatribble7961 Awesome, glad you like em!
@randatebina7421
@randatebina7421 4 жыл бұрын
I do not own the Pil Library What do I do ?!
@Codemycom
@Codemycom 4 жыл бұрын
It's free, follow the video and pip install from the terminal
@learnwithstranger575
@learnwithstranger575 4 жыл бұрын
When you do something wrong then why you blame Vaga's huh?
@Codemycom
@Codemycom 4 жыл бұрын
huh?
@mister6497
@mister6497 Жыл бұрын
you messed up on the title it says ''tKinter' instead of 'TKinter'
@Codemycom
@Codemycom Жыл бұрын
So?
@yamin1702
@yamin1702 4 жыл бұрын
I am having a problem with a login system. Here's the code: from tkinter import * from tkinter import messagebox win = Tk() win.geometry("500x500+100+100") win.title("Hello") lbl = Label(win, text = "Please login below").pack() lbl = Label(win, text = "").pack() lbl = Label(win, text = "").pack() lbl = Label(win, text = "Username").pack() entry1 = Entry(win).pack() lbl = Label(win, text = "").pack() lbl = Label(win, text = "Password").pack() entry2 = Entry(win).pack() lbl = Label(win, text = "").pack() error_text= StringVar() login_label = Label(win, textvariable=error_text, font=('bold', 14), pady=5, fg='red').pack() username = "aaa" password = 111 def login(): if entry1 == username and entry2 == password: new = Tk() new.geometry("500x500+100+100") new.title("Hello new") win.destroy() btn = Button(win, text = "Login", command = login).pack() mainloop() when I try to run it with the correct username and password, the new window doesn't open even though I have defined the username and password. I have written "new = Tk() " under the function as well.
@Codemycom
@Codemycom 4 жыл бұрын
What error do you get? What does the terminal say?
@yamin1702
@yamin1702 4 жыл бұрын
I don't get an error and there is nothing on terminal. The problem is that the following function just does not work: username = "aaa" password = 111 def login(): if entry1 == username and entry2 == password: new = Tk() new.geometry("500x500+100+100") new.title("Hello new") win.destroy()
@Codemycom
@Codemycom 4 жыл бұрын
@@yamin1702 entry.get() and entry2.get()
@Binford35
@Binford35 4 жыл бұрын
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.
@Codemycom
@Codemycom 4 жыл бұрын
Yep...you can use global variables too, to get around that...
@Codemycom
@Codemycom 4 жыл бұрын
You're welcome!
@audisgamers6681
@audisgamers6681 3 жыл бұрын
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!
@lynnmcgarry2580
@lynnmcgarry2580 3 жыл бұрын
3 days I've spent on this and you solved it in a couple of mins. Can't thank you enough.
@Codemycom
@Codemycom 3 жыл бұрын
Awesome, glad you found it!
@sahilnigam4536
@sahilnigam4536 3 жыл бұрын
ofc a udemy ad is required before the video starts
@Codemycom
@Codemycom 3 жыл бұрын
Yeah, that's how youtube works.
@twojdobrykolega8597
@twojdobrykolega8597 Жыл бұрын
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
@gold_miner.
@gold_miner. 3 жыл бұрын
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
@vijaykumargupta9259
@vijaykumargupta9259 3 жыл бұрын
can you plz help with how first window get close when 2nd opens
@johnpro2847
@johnpro2847 5 жыл бұрын
cool... got one working already, Thanks John.How do you bring the 2nd window back. Destroy command seems to do just that !!!
@Codemycom
@Codemycom 5 жыл бұрын
Glad to hear!
@manikandannatarajan9665
@manikandannatarajan9665 4 жыл бұрын
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
@Codemycom
@Codemycom 4 жыл бұрын
Great to hear!
@WHWrooolz
@WHWrooolz 4 жыл бұрын
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?
@Codemycom
@Codemycom 4 жыл бұрын
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.
@WHWrooolz
@WHWrooolz 4 жыл бұрын
Codemy.com thanks!
@TogrulKazimov
@TogrulKazimov 4 жыл бұрын
I got this error: NameError: name 'Toplevel' is not defined
@Codemycom
@Codemycom 4 жыл бұрын
Check your code for typos
@uselessvirus3827
@uselessvirus3827 Жыл бұрын
Freshman here, It is possible to add animation to my rock paper scissors game and picture? I desperately need help💀🙏
@Codemycom
@Codemycom Жыл бұрын
You can add a timer
@greg_pizzatower
@greg_pizzatower 2 жыл бұрын
just what i needed thanks
@Codemycom
@Codemycom 2 жыл бұрын
Nice!
@sandrogianni1821
@sandrogianni1821 2 жыл бұрын
please, but in second window, how insert Entry, label and execute whith button? alwwais in second windows
@Codemycom
@Codemycom 2 жыл бұрын
The same way as with a first window.
@globalguru21
@globalguru21 3 жыл бұрын
please kindly explain how to create second window inside the first main window, just like MDIForm in Visual Basic.
@nagol2678
@nagol2678 2 жыл бұрын
Thank you for the video! How do I add a frame to a Toplevel() window? I can't seem to find an answer anywhere.
@WalterWhite-dr2yz
@WalterWhite-dr2yz 4 жыл бұрын
The image I want to display in the second window is being displayed over the first window. What should I do?
@Codemycom
@Codemycom 4 жыл бұрын
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)
@WalterWhite-dr2yz
@WalterWhite-dr2yz 4 жыл бұрын
@@Codemycom thx man this saved me a lot of time
@Codemycom
@Codemycom 4 жыл бұрын
@@WalterWhite-dr2yz You mean it actually worked? lol ;-)
@WalterWhite-dr2yz
@WalterWhite-dr2yz 4 жыл бұрын
Ya dude ur great 👍
@Codemycom
@Codemycom 4 жыл бұрын
@@WalterWhite-dr2yz ha thanks
@gold_miner.
@gold_miner. 3 жыл бұрын
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
@prbprb2
@prbprb2 3 жыл бұрын
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
@Codemycom
@Codemycom 3 жыл бұрын
in the same way you put them in the main window...instead of root, use the name of the window
@prbprb2
@prbprb2 3 жыл бұрын
@@Codemycom Thanks very much. It is implicit in what you covered, but now I get it.
@robcox500
@robcox500 4 жыл бұрын
How is it that the image 'my_img' is not associated with a window?? Is there some default here?
@Codemycom
@Codemycom 4 жыл бұрын
Sorry, I'm not sure what you're asking. You did associate it with a window, when you listed it as root.
@robcox500
@robcox500 4 жыл бұрын
@@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!
@laurentreynaud4404
@laurentreynaud4404 3 жыл бұрын
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
@Codemycom
@Codemycom 3 жыл бұрын
You're welcome 😊
@sumedhasharma1984
@sumedhasharma1984 3 жыл бұрын
So you used Google translate to write this comment??
@laurentreynaud4404
@laurentreynaud4404 3 жыл бұрын
@@sumedhasharma1984 yes, I'm sorry but my english level is very low :(
@ForOptomeLearning
@ForOptomeLearning 4 жыл бұрын
Do we need to import ImageTk ?? Won't PhotoImage alone be sufficient enough to load the image ??
@Codemycom
@Codemycom 4 жыл бұрын
Try it without and see
@ForOptomeLearning
@ForOptomeLearning 4 жыл бұрын
@@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.
@sulagnadas908
@sulagnadas908 5 жыл бұрын
Why the Label thing doesn't work in my second window😥.... The error says... Can't invoke 'label' command: the application has been destroyed Plss help me out someone... I need to complete my project 😫
@Codemycom
@Codemycom 5 жыл бұрын
Check your code, you likely have a typo
@akpanvincent1499
@akpanvincent1499 4 жыл бұрын
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.
@Codemycom
@Codemycom 4 жыл бұрын
You can learn everything you need to do that by watching the videos of this playlist.
@fastandfurious2171
@fastandfurious2171 Жыл бұрын
why I can't use from tkinder import * it showing error at from that is unused import(s)
@Codemycom
@Codemycom Жыл бұрын
you misspelled tkinter
@fastandfurious2171
@fastandfurious2171 Жыл бұрын
@@Codemycom sorry but while typing I used correct spelling of tkinter, did I need to install all imports like Button, Label,Tk....
@fastandfurious2171
@fastandfurious2171 Жыл бұрын
note: typing in VS Code not in this comment
@Codemycom
@Codemycom Жыл бұрын
@@fastandfurious2171 I would never use VS Code for tkinter. I have no idea how you need to setup VS Code for tkinter
@Rlearning1
@Rlearning1 Жыл бұрын
Great help! I was stuck on the image part for many hours but found no solution until I found the global var part. Thanks!
@Codemycom
@Codemycom Жыл бұрын
Welcome
@Kalpesh2331991
@Kalpesh2331991 3 жыл бұрын
button on root screen will open second window multiple times, how can i prevent to opn window, if it is already opened once
@Codemycom
@Codemycom 3 жыл бұрын
Use a counter and if statement
@lucianmardale10
@lucianmardale10 2 жыл бұрын
Hello. Did you succeed with a counter? Me no :(
@lucianmardale10
@lucianmardale10 2 жыл бұрын
@@Codemycom I just saw this video kzbin.info/www/bejne/fpDdi5x_odN1bq8 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!
@Codemycom
@Codemycom 2 жыл бұрын
@@lucianmardale10 sure, why not...just change the counter
@Beast80K
@Beast80K 4 жыл бұрын
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.
@Codemycom
@Codemycom 4 жыл бұрын
Disable the button after one click... myButton['state'] = DISABLED
@AdityaSharma-no5ix
@AdityaSharma-no5ix 4 жыл бұрын
can't I use Tk() instead of Toplevel() ? Edit:whats the main difference
@Codemycom
@Codemycom 4 жыл бұрын
No, you already use Tk()
@thetwenty6784
@thetwenty6784 4 жыл бұрын
Tkinter looks ugly. Is there any GUI of python for Android Irrespect of Kivy.
@Codemycom
@Codemycom 4 жыл бұрын
It looks how you code it...
@thetwenty6784
@thetwenty6784 4 жыл бұрын
@@Codemycom can you refer some apps designed in tkinter
@Codemycom
@Codemycom 4 жыл бұрын
@@thetwenty6784 I have no idea
@thetwenty6784
@thetwenty6784 4 жыл бұрын
@@Codemycom okay That's Great.
@P_Rodd
@P_Rodd 3 жыл бұрын
@@thetwenty6784 I think IDLE is written in Tkinter
Open Files Dialog Box - Python Tkinter GUI Tutorial #15
12:34
Codemy.com
Рет қаралды 192 М.
How to Pass Data between Multiple Windows in Tkinter
18:19
CodersLegacy
Рет қаралды 29 М.
Which One Is The Best - From Small To Giant #katebrush #shorts
00:17
How To Get Married:   #short
00:22
Jin and Hattie
Рет қаралды 21 МЛН
🍉😋 #shorts
00:24
Денис Кукояка
Рет қаралды 3,4 МЛН
Using tkinter with classes
28:23
Atlas
Рет қаралды 65 М.
Create Stunning Python GUIs in 10 Minutes With Drag & Drop
11:38
Coding Is Fun
Рет қаралды 71 М.
Radio Buttons with TKinter - Python Tkinter GUI Tutorial #12
17:44
Python Tkinter GUI Application With Multiple Pages | Switch Pages in Tkinter | Tkinter Pagination
42:33
Modern Graphical User Interfaces in Python
11:12
NeuralNine
Рет қаралды 1,5 МЛН
Menu Bars With tKinter - Python Tkinter GUI Tutorial #46
11:02
Codemy.com
Рет қаралды 101 М.