What does pygame.display.set_mode() do? - python

I have recently started learning python and decided that a fun way to learn would be to use pygame.
The following is some code that sets up the the window.
screen = pygame.display.set_mode((1200,800))
Would pygame be a file in which the file display is located?
I assume display refers to a file in which the method set_mode() is located.

If you already have a basic understanding of Object-Oriented Programming but are learning python through pygame, then Have a read through this tutorial: pygame - Setting Display Modes
Setting the display mode in pygame creates a visible image surface on the monitor. This surface can either cover the full screen or be windowed on platforms that support a window manager. The display surface is nothing more than a standard pygame surface object.
If you are starting to learn python and or programming from scratch, you might find more value in learning some basic programming and problem-solving concepts first, then come back to pygame.
I'm not affiliated but find the Hacker Rank 30-day challenge as a great learning tool, it is unique in tutorial sites as it is language agnostic and allows you to learn multiple languages at the same time if you wish to do so! It is also a good environment to learn in as there are fewer IDE features, forcing you to understand more before you can move on.
The average desktop IDE is not a great place to learn how to program because it will often have features like Intellisense, Autocomplete and other smart refactoring tools that allow us to write code quickly, but they allow you to "cheat" and skip over vital underlying mechanics that you need to understand if want to take advantage of abstract knowledge resources you may find around the web, like solutions in Stack Overflow!
Once you have a better understanding of syntax and how to use your chosen IDE, then go back to your pygame learning, walk before you run.

Related

Biomorph Implementation in Python

I'm trying to create a Python implementation of Dawkins' biomorphs as described in his book, The Blind Watchmaker.
It works like this: A parent organism is displayed, as well as its offspring which are just mutated versions of the parent. Then the user clicks on a descendant it wants to breed, and all the offspring will "evolve" based on cumulative selection.
What I'm unsure of is how to get started in Python. I've already created genetic algorithm and l-system programs that are supposed to be used. The l-system program evolves trees given certain parameters (which is my goal in this biomorph implementation), and the genetic algorithm program evolves the genotypes that are created in the l-system program.
What library would be good to use (turtle, pygame, etc)?
I am familiar with turtle, but the documentation says, "To use multiple turtles an a screen one has to use the object-oriented interface." I'm not sure what that means. The reason I thought of using multiple turtles on a screen is to have the the parent and its descendants displayed on one screen, as they are in online apps. Then the user can click on the organism it wants to breed by using mouse events. Is this a good idea, or is there better way to do it?
Thanks in advance.
Depending on graphical requirements, I would say that for a lightweight app you could get away with PyQt or PyGame. For more demanding real-time graphical requirements you could use something like PyOgre or PyOpenGL.
You may need to also research graph-layout/data-visualisation algorithms or libraries (e.g. dot) depending on your UI goals.

Programming a GUI Like Steam?

So I've been tinkering with a few different GUI's but I haven't been able to even find a point to begin researching this question:
How do I make a GUI like Steam (Digital distribution app) has? More specifically, I'm interested in how they manage to make their SHIFT+TAB menu pop up in-game, without disrupting/pausing/effecting the game. I've been somewhat successful in making a GUI window "stay on top" when a game is in window mode, but Steam pops this little menu up over the top of a running, fullscreen game.
That's what I'm interested in learning about. Any info would be much appreciated. :)
Sorry if this isn't the correct place to post this. I wasn't sure exactly where to ask.
PS> Preferably something I could implement in Python!!!
The Steam overlay/notification system hooks into games via Direct3D or OpenGL in Windows (depending on the game) from my understanding (as it doesn't work for games that aren't Direct3d/OpenGL like Diablo).
It uses the same rendering libraries that the game uses and thus can overlay their menus natively.
As for Python implementations, you can check out http://directpython.sourceforge.net/ and http://pyopengl.sourceforge.net/ as a start (for DirectX and OpenGL libraries respectively) but can I warn you that I don't think this is as simple as you're hoping.
Hmm, that looks very much like they are using Adobe AIR or maybe Flash.

Picking a suitable GUI framework for project

I have a project where I have to show some sort of changing bar graph with results from a function. This bar graph should be in colour and 3d. I want it to look good since it's an open source educational program where it teaches the user about different voting systems and how they effect the outcome of an election. I would like to use python but I have no idea about using GUI frameworks since all my work in python has been command line based. Your help will be appreciated.
For 3D graphics, you might want to use OpenGL with a game framework, such as PyGame or Pyglet. Use matplotlib as TJD suggested in the other answer.
As for GUI frameworks, they generally won't help much with 3D graphics:
PyQt is one choice; I see you already have it in the question tags. PySide is very similar to PyQt, but with a nicer licence.
Then there's tkinter (in the standard library), wxPython, and pyGTK – I hear all of them are good, though I don't know them personally.
Pick one and stay with it. It'll take some time to learn if you're not experienced, so don't expect results too soon.
You might want to look at matplotlib, which is probably the most widely used library for doing graphs, including 3-D.

Interactive movie / video processing with PyQT / OpenCV

I am starting out on a project in which I need to build a customized annotation tool for movies and video. Some person (not technically minded) will need to pop open a GUI that I create, open either a video file or a directory of frames that result from chopping up a video file, and then use a window (much like QuickTime or VLC player, etc., i.e. a video window with a simple slider bar allowing the user to move back and forth at will). In this window, the user will be able to click on interesting points, give them semantic labels and meta-data (such as whether or not the point is occluded by something else in the picture), and then basically "press go" and start a tracker. The tracker will follow the points, frame by frame and the user can press the space bar or something to move forward and backward. The idea is to allow the human to intervene any time the tracker gets confused, but hopefully the tracker works well enough that humans don't have to hand-label every frame in an entire multi-thousand frame video sequence.
I am planning to do this all in Python, (a) because it is the language I know best for non-trivial programming, (b) I have easy access to both OpenCV Python (for image processing algorithms) and PyQt which seems to have a powerful enough GUI toolbox for what I want to do and (c) some other aspects of this same project are being developed by other programmers to work in Python and with MySQL databases. Python just seems like the natural choice to streamline it all together.
I am experienced using computer vision algorithms for the tracking, and I am reasonably sure that I can figure out simple PyQt GUI devices for making points clickable, buttons, entering simple text data, etc. However, the part I am having trouble understanding is how to actually construct my own video window with a slider bar that either moves ahead according to a frame's number or else is actually manipulating a video file. Can I leverage other movie players like VLC from within PyQt when programming in Python? Any suggestions or links that describe similar movie/video editing GUIs and how to develop them at home would be greatly appreciated.
Qt(PyQt) has a good multimedia support via Phonon module. You can easily use that module to achieve Video window, it can provide an easy-to-use video player and you can get playing position etc.

Creating an image editing application in Python

I need a tile/sprite editor kind of like Pixen, but I couldn't find one for Windows so I thought it might be a good exercise for me to try and put one together. I use Python, so are there any libraries out there that are suited to the task of putting together a simple tile/sprite editor?
You just need a gui toolkit (gtk, qt, wx) a image library (PIL) and 500 hours of free time ...
Have you looked at the Python Imaging Library (PIL)?
So, the fact is that creating a complex app with a nice UI takes time - I am just expanding a little bit on the answer by THC4k.
PIL, at least PIL alone is useless for this: it does have some functions to manipulate images, but the complicate task here is creating and tunning your desired UI.
That's where the widgets toolkits come in: You would have to pick a toolkit platform that can offer you buttons, images, load and save the image files, maybe some specialzed widgets you can use to create your color swatches, etc.
both GTK+ and QT4.5 have a liberal license, are very complete and very unpythonic on their use :-(
(While you are at it, when using these libraries and toolkits our app can easily be multiplatform: you don't have to make it windows specific, it is equally easy to create an app that will run on Windows, Linux and Mac using python and either GTK+ or Qt4)
One thing I would suggest is for you to learn to proper use GIMP: it is an Image editor, and certainly it will lack a lot of tools you are needing for sprites: but you can expand it's capabilities with Python plug-ins. On the other hand GIMP does have thousands of features that you'd no longer will need to create for your stand-alone app. (think on layer support, color filters, image rotation etc...)
Check around on how to install GIMP with Python support on Windows, then spend some hours learning the app, with some book-like text around preferably so you can find the hidden features.
Ah, ok, finally:
If you want a very simple thing, just for the taste of "i did it" - you can use Pygame: You have to do all the drawing on the window, including text - but have straighter access to pixels, colors, mouse clicks and coordinates than with GTK+ or Qt, in a sense it would be a lot less of overhead for you to learn in terms of API's and internal working.
You could try PyGame but, seriously, you couldn't find a freeware graphics editor for Windows??!!
EDIT: In the past I've used Aha-Soft's IconXP for pixel work, but it costs USD 30 and doesn't offer all of the Pixen features that I guess you'll want.

Categories