Python Forum
How old am I? (first gui script) - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: How old am I? (first gui script) (/thread-11194.html)



How old am I? (first gui script) - Nwb - Jun-27-2018

Original script:
Apart from the fact being that this is is my first fully-made gui script ever, this script is also coming from a newbie! So I might not understand all terms.. Angel

I spent a lot of time making sure everything was correct. But please suggest me better alternatives or warn me of bad practices I might have used. Big Grin

The script is pretty simple it gives you three input fields, makes sure you type in correct values (example cannot type 3 as first digit in year's field) with the help of textvariable, and pops up how old you are in minutes when you click on "That's me!".

Also, when you run the tkinter messagebox version (below over here), you will notice that the button gets stuck every time the message pops up? I changed the module because of that reason do you guys know why that is happening?

If you want to run the script here are instructions:


Use this version of the code instead (uses tkinter messagebox instead) if you do not have pymsgbox:

-> Known issue: Button gets stuck when message pops up. Don't know why that happens.



Oh and here are the pictures I used just by the way:
(I'll upload them later Razz )

Thanks for reading!


RE: How old am I? (first gui script) - buran - Jun-27-2018

for start:
Read PEP8 for Style Guides, e.g. naming conventions
Read about String formatting, e.g. instead of defining function to add commas
Use IntVar, instead of StringVar
Use datetime module to construct date from user input and it will be way easier to check the input - e.g. is it valid date, is it before today, etc.


RE: How old am I? (first gui script) - Nwb - Jun-27-2018

Thanks I appreciate it. Do you face what I did when running tkinter's messagebox? Every time the messagebox pops up the button that spawns the messagebox gets stuck.. I was wondering if it's just me.


RE: How old am I? (first gui script) - buran - Jun-27-2018

I didn't run it


RE: How old am I? (first gui script) - buran - Jun-27-2018

Normally you would display the result in a widget, e.g. label, not messagebox.
Also, get rid of using global variables


RE: How old am I? (first gui script) - Nwb - Jun-28-2018

(Jun-27-2018, 03:46 PM)buran Wrote: Normally you would display the result in a widget, e.g. label, not messagebox. Also, get rid of using global variables

I want a secondary window to display errors (the result is just temporarily using the msgbox in the future it will pop a window with a picture in it), so messagebox from tkinter seemed very convenient. But this malfunction seems to occur to me with both my GUI scripts so I have to use another function instead of messagebox.