Sign in to follow this  

What is a GUI? And more related questions...

This topic is 3041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know that GUI stands for Graphical User Interface. I also understand that in basic terms it allows programs to have visual objects the user can interact with. I would like some help understanding GUI creation as it relates to programming though. Can I create a GUI using python without any other modules/packages or additional libraries? Why/Why not? I've been trying to find some tutorials on GUI creation using Python, and everything I find says I need to use a package (such as PythonCard or TkInter, etc). What I'm having a hard time grasping are the basics behind it. Why do I need to use a different package? Why can I not simply create a GUI using just python? What's in the packages that isn't in Python? Basically, before I start messing around with something like PythonCard, I want to know why I have to use PythonCard to create a GUI. Also, can I just use python and pygame to create a GUI(is pygame one of the package options, or would I still need a 3rd item to create a gui?). I guess I'm having a hard time explaining my question here, it just seems that most of the help on GUI creation on the web simply says "go use this program/package" but doesn't explain the need for the package, the reason you can't simply create a gui in python, etc. I hope that made some sense. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Landshark
Can I create a GUI using python without any other modules/packages or additional libraries? Why/Why not?


You can do it with modules that come with Python. You cannot do it with just the language itself. You cannot practically do that with any language on a modern home computer, for two reasons.

#1, it's far, far too much work. Much of the point of these other dependencies is to take care of details like positioning math and event processing (i.e. figuring out where the mouse pointer is and whether the user has clicked on something), so that you can worry about the things that actually make your GUI your GUI (i.e. what happens when the user clicks on a specific thing). Typically, the GUI library will run the main loop of the program, and call functions that you write ('event handlers') when something interesting happens (such as a mouse click), after you've configured it to tell it what to call in which circumstances.

#2, on a modern system, you don't have permission. Creating the GUI involves drawing things on the screen, but your program isn't the only thing drawing things on the screen. The operating system is constantly sharing out CPU time to all the programs running on the computer, figuring out the order of windows to display, taking care of overlaps, drawing menu and title bars and window resizing widgets, etc. It also provides functions that can be called to draw things like scroll bars, buttons and checkboxes, and pop up dialog boxes - so that they'll all have a consistent style (the one created by the OS's code) throughout all the programs on the computer (unless a program goes out of its way to do custom drawing).

To get anything done at all, you first need to talk to the operating system, through its interface, in order to request a window of some sort. Then you effectively tell the operating system to draw things relative to the window, and then it figures out whether they actually get drawn, based on (a) how big the window is versus the thing-to-be-drawn's position, and (b) any windows that are overlapping yours. That interface is defined by the operating system's code, and not by any programming language.

But with the libraries, you don't even have to work at that level - they make the calls for you, and present an interface that can be understood more easily.

Quote:
I've been trying to find some tutorials on GUI creation using Python, and everything I find says I need to use a package (such as PythonCard or TkInter, etc).


Tkinter (the 'i' is not normally capitalized) comes with Python. However, it's not very powerful and can be quite awkward to use. Pythoncard is not too bad, although I had some annoyances with it. If you're more daring, you could try wxPython, which is a little closer to the metal than Pythoncard (actually, Pythoncard is implemented in terms of wxPython). Remember, with great(er) power comes great(er) responsibility.

Quote:
Also, can I just use python and pygame to create a GUI(is pygame one of the package options, or would I still need a 3rd item to create a gui?).


You can certainly do it with Pygame as well, although you won't have out-of-the-box support for application-style things like checkboxes and scrollbars and buttons. Of course, people who are making games often don't want those things (ever notice how dialogs in games generally don't look at all like dialogs in word processors?)

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Quote:
Also, can I just use python and pygame to create a GUI(is pygame one of the package options, or would I still need a 3rd item to create a gui?).
You can certainly do it with Pygame as well, although you won't have out-of-the-box support for application-style things like checkboxes and scrollbars and buttons.
There are however many 3rd party libraries which implement these features.

Share this post


Link to post
Share on other sites
Thank you Zahlman for your detailed reply.

I've really been enjoying Python so far, I'm about 1.5 weeks into learning it completely on my own. Your reply helped me wrap my head around the concept a bit more and I appreciate it!

I made my first game today from scratch (just a simple 'guess the number' game), but I'm hoping to use it along with a stock profit calculator (really really basic) program I made to practice making GUI's in python. Although I'll probably end up using pygame for both GUI's just to get use to how it works.

I'll check out wxPython as well.

Share this post


Link to post
Share on other sites

This topic is 3041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this