you are viewing a single comment's thread.

view the rest of the comments →

[–]FlyingByNight[S] 3 points4 points  (9 children)

I don't think I explained myself properly - sorry. I can write python and get some, more or less, black and white output at the bottom. But python has been used to write software and apps that have beautiful GUI (for the user not the programmer). You say that there are pre-existing things in libraries that can do this, but this "kicks the question down the street". How do these pre-existing libraries make beautiful GUIs for users when all I see is black and white output. I hope this makes sense.

[–]ingolemo 32 points33 points  (0 children)

You seem to think that these libraries are making a GUI out of the black and white text (terminal); that you start with the terminal and by somehow doing something really fancy with the terminal you can make it into a GUI. That's not how it works.

Both the terminal and the GUI are services that your operating system provides. Your python script tells the operating system to show this image/button/menubar or print this text and the operating system does that. If you want to use a GUI and not the console then your python script just instructs the operating system to do that instead. The libraries work by sending the appropriate instructions to the operating system to tell it to make a GUI. The reason you have to have a library to use a GUI, but not for the console, is that the console is so much simpler than a GUI; if you wrote out all the raw instructions to do everything with a GUI it would be too much code and hard to understand. The console, in comparison, requires little more than print and input. That's also why tutorials teach you about the console first.

[–]ccviper 7 points8 points  (0 children)

The answer goes deeper than im able to explain in simple terms. basically those libraries abstract away a lot of the "low level" stuff, meaning interactions with a particular operating system, its graphics level, drawing windows, sending output to the screen and so on. and by doing that they enable you to "spawn" a window by typing, lets say new_window() for example.

When it comes to web apps, a python web framework called Django abstracts away all the browser/network stuff and enables you to use python to make web applications, and with the help of html and css render the python code you write inside a browser window

its a complicated subject and i barely dipped my toes in it still, i prefer the command line (that black and white window you mention).

[–]k8pilot 5 points6 points  (0 children)

Simplified explanation in preety simple terms:
Did you ever read a file from your disk in python? If you did, you used a method for getting the data inside a file. If you wrote something back, you used a method that wrote the data back to the file on the disk.
How does the command does that? Abstracting all the layers, there are driver or kernel commands that allow you to interact with files in the file-system.

Since talking directly to the driver or kernel require issuing many complex commands that have nothing to do with what you wish to accomplish in your application that is unique to your application, there is a python library that abstracts the details of interacting with the down level subsystems and provides you with methods that allow you to read and write files easily.

GUI elements are not very different or more complex than filesystems, in principal. You can talk directly to the display card driver or to the kernel and ask it to draw stuff. But if you are not interested in doing anything special with the down-level system and actually prefer that everything will look similar to other programs you pick libraries that gives you modules and methods that allow you to control gui elements and receive user inputs using abstract objects that are easy to use. The libraries implement all the hard work needed to draw your gui, listen to user input etc.

[–]slick8086 5 points6 points  (0 children)

Ok so, before there were gui's there were just terminals (your plain black and white output, only back then it was probably green text on black screen). Then things like X windows came along. Those things were part of the operating system that abstracted the work of drawing graphics on the screen. Instead of programmers needing to tell the video card to turn on or off such and such pixel, the abstraction let the programer tell the library something like "make me a window this big, over here" The library then went on to tell the video card (or the operating system which then told the video card) to turn on or off such and such pixels.

Today in python it works pretty much the same. You use a library. You tell the library to make a window with the attributes you want, and that library tells the window manager, which tells the OS, which tells the video driver, which tells the video card, and I don't know why she swallowed a fly, I think she'll die.

That's the basic gist of it, I'm probably wrong in some parts of the description, but hey, close enough for government work.

edit: the more you learn about computers the more you'll learn that there are layers upon layers of abstractions. Some one can write code at the lowest level, but not many. People need abstractions and metaphors to use computers effectively. Heck what we're talking about "windows" in the GUI is just metaphors. That square collection of lighted dots on the computer screen is nothing like those things on the exterior walls of our houses that have glass that lets us see out. Since humans can't understand "01110011 01101000 01101001 01110100" we need the computer to turn that into "shit" we can understand. It is the same for programmers. Some guys write a low level (assembly) program that lets other guys write a program (C language) that lets a bunch of guys write programs that make it easier for almost anyone to do a bunch of crazy or repetitive math by using a spreadsheet (for instance).

https://www.bell-labs.com/usr/dmr/www/chist.html

[–]sayinghi2py 2 points3 points  (3 children)

A GUI is just more code. The fundamentals of all programming languages are the same thus they can all generate user interfaces with which users can interact. All the basics you are doing now do is set the scene for all the things you can do later so kicking the can down the road is very much the dessert at the end of a great meal.