I am writing a text based game in python and as you'd expect, it has many questions with multiple answers e.g. yes/no.
I have been been using the usual, input your answer, answering technique, but I was hoping to make it a bit more interactive in answering some options, such as the main menu. I do not want a full on GUI but is there some way to have something similar to, for example, the modern BIOS menu, where you use the arrow keys to navigate, and press enter to select?
http://www.washington.edu/lst1/help/computing_fundamentals/troubleshootingxp/img/bios.gif
Thanks for any reply's, whether it's possible or not!
P.S. I would rather not have to download any plugins etc, because I have to be able to use this at school where I cannot use them.
This is a rather open-ended question (not have to download any "plugins")? But what you want is the curses library, to which Python has an interface with its curses module. The Python docs provide a simple tutorial for using it.
There is also a library called Blessings which provides a nicer, more modern object-oriented interface to curses. I haven't tried it but it's well supported and looks pretty good.
Take a look at the Urwid library: http://excess.org/urwid/
(I know you'd like to not use an external module, but that means you'll essentially have to reimplement most of CURSES yourself, and that's a road you really don't want to take)
Related
I wrote a function that receives input as a string, modifies it, and outputs a string. I want to make it so that my non-computer savvy friends can use it, by adding a graphical user interface. I want something very simple: A box where they type in the text, a button that along with hitting "Enter," submits the text, and then a place where it displays the result after my function had modified it. I just want a way to receive input and to write output to a GUI in a way that a regular person can understand. I have no experience with GUIs.
Update
In the end I used XCode to create the GUI and PyObjC to pass the data from GUI to Python in a sort of "frontend-backend" setup.
You may be interested to get a look at http://zetcode.com/
there is a bunch of tutorial about wxPython, PyGTK and PyQt
It should guide you.
Jordi
Does your program have to be python? (as tagged) Your description sounds like a very straightforward task. In that case, have you considered JavaScript + HTML? Your users wouldn't need to download and install anything new, and most people have a good grasp of how to create/use web page forms.
If you're committed to a python implementation: There are a variety of different GUI toolkits (ways of creating the graphical user interface), but which one you choose will depend on how you want your program to look, what operating system you run on, ease of programming, and a variety of factors.
The widgets you describe are fairly simple (text box and button), and you might be able to accomplish your goals using Tk / Tkinter, python's "de facto standard GUI". The advantage of this GUI toolkit is that it's bundled with python on most operating systems, hence (so long as your friends have python installed) they're ready to go. If you don't have experience building complicated installers, then you'll find that users wander off when you require them to install a dozen modules on their own. The TK script would also run on any OS.
Convenience aside, the disadvantage of Tkinter is that Tk is a fairly old and limited framework in the form commonly found with python, and it can be painful to work with for more complicated programs. (some of the online tutorials have typos like mixed case or missing quotation marks) For your task, though, the basic layout and code are pretty simple: see the TkDocs site for a demo that you can adapt.
http://www.tkdocs.com/tutorial/firstexample.html
If you are familier with C# , than you can use IronPython,
just import the Form libraries, make simple form, by putting Lable, Textbox and Button, and refer to that textbox value on Button click. you can get the WOW Gui for Python, with IronPython
Ref : IronPython
We are in the process of standing up a UI on top of a python system. This is all throw away code, so we want something quick, yet presentable.
We will have a couple of "interfaces" but they will be of two types. One will be control, it will basically be sitting on top of a python thread, and accepting requests from the user.
The other will be more of a display screen that will need to be able to display images, and some classic "grid views" of text to the user.
We pretty much know we could* do all of this in HTML but wasn't sure what would be the best way to interact with the core python code?
Anyone know of a good UI python presentation layer? Since we know we can do all of this in HTML/Jquery pretty quickly, we are also open to suggestions on how to integrate this with a web server..
Any suggestions? Really interested in finding out if there is any way to use python as the back end to a webserver.
Let me know if you all need more information.
I like wxPython. The demo application is excellent and lets you browse, tweak and re-run the code right in the demo.
We have found the DJango meets our needs. It is a pretty slick mvc style python web stack. Really is easy to use, and very quick to develop in. I will say that the ORM layer is a little young so it is hard to do some simple queries, but luckly since this is throw away code we can just use native sql.
Tkinter is probably going to be the solution you can use quickest. Its API is simple and straight-forward, and you probably already have it installed.
As the other 2 classic Python GUI options have been given already, I feel duty bound to suggest PyQt :)
Using QT Designer I've found it much simpler than TKInter to get some basic GUIs up and running. Build your GUI up in a WYSIWYG way, then hook it up to the back-end logic. I've also found that the large amount of C++ help on QT available on the interent usually translates more or less directly across to PyQt. The resources available for TKInter are IMO pretty obtuse, and simply stop as soon as you want to do anything more interesting than Hello World. YMMV.
The Rapid GUI Programming with Python and QT book is a fantastic resource. Had me programming real applications in no time.
does anyone know if there a vba style compiler/gui for python. i am using the regular IDLE and it is difficult to navigate from function to function. with the VBA editor you are able to skip from function to function with a listbox. does anyone know if such a thing exists for python?
Eclipse with PyDev can do this. Eric apparently can too.
there are several Frameworks for GUI programming and some GUI-Editors/IDEs
a summery on what frameworks exists, is available in the python wiki
Which to use depends largely on your preferences, the plattform you are using and your skills
Learn a decent text editor, and learn it well.
In vim for instance, I would search for def func and get there WAY faster than you ever could using your mouse in a drop-down list.
[PyScripter](http://code.google.com/p/pyscripter/"This is the download page.") is good and is actively developed.
My machine has two audio inputs: a mic in that I use for gaming, and a line in that I use for guitar. When using one it's important that the other be muted to remove hiss/static, so I was hoping to write a small script that would toggle which one was muted (it's fairly inconvenient to click through the tray icon, switch to my input device, mute and unmute).
I thought perhaps I could do this with pywin32, but everything I could find seemed specific to setting the output volume rather than input, and I'm not familiar enough with win32 to even know where to look for better info.
Could anybody point me in the right direction?
Disclaimer: I'm not a windows programming guru by any means...but here's my best guess
Per the pywin32 FAQ:
How do I use the exposed Win32 functions to do xyz?
In general, the trick is to not
consider it a Python/PyWin32 question
at all, but to search for
documentation or examples of your
problem, regardless of the language.
This will generally give you the
information you need to perform the
same operations using these
extensions. The included
documentation will tell you the
arguments and return types of the
functions so you can easily determine
the correct way to "spell" things in
Python.
Sounds like you're looking to control the "endpoint device" volumes (i.e. your sound card / line-in). Here's the API reference in that direction.
Here's a slightly broader look at controlling audio devices in windows if the previous wasn't what you're looking for.
Here's a blog entry from someone who did what you're trying to do in C# (I know you specified python, but you might be able to extract the correct API calls from the code).
Good luck! And if you do get working code, I'm interested to see it.
I had a similar problem and couldn't figure out how to use Windows API's to do what I wanted. I ended up just automating the GUI with AutoIt. I think that will be the fastest and easiest solution (albeit a "hacky" one). As I answered earlier today, you can use AutoIT from within Python.
You are probably better off using ctypes - pywin32 is good if you are using one of the already included APIs, but I think you'll be out of luck with the sound APIs. Together with the example code from the C# link provided by tgray, use ctypes and winmm.dll, or alternatively, use SWIG to wrap winmm.dll. This may well be quicker as you won't have to build C structure mapping types in ctypes for the types such as MIXERCONTROLDETAILS which are used in the API calls.
tgray seems to have pointed you in the right direction, but once you find out the right Win32 APIs to deal with, you have a couple of options:
1) Try using pywin32...but it may or may not wrap the functionality you need (it probably doesn't). So you probably only want to do this if you need to use COM to get at the functionality you need.
2) Use ctypes. It's generally pretty easy to wrap just about any C functionality with ctypes.
3) If the C# example looks like what you need, you should be able to translate it to IronPython with fairly little effort. Might be easier than using the C API. YMMV, of course.
I should say I'm looking for something interactive, equivalent to what Nevron offers in it's .NET Diagram product, where a user can create nodes, interact with them by dragging them around, etc. I know there's GraphViz, but as far as I know it's static, and just renders a graph/diagram, there is no interaction with it.
I have a bad feeling there is nothing as rich as this in the cross platform world for Python or any other script language, but maybe I've missed it.
Ubigraph is probably not what you want, but is still really excellent.
I have been searching for a solution to this myself for quite some time, and have just come across an Apache 2.0 licensed project based on Cairo and GTK, called Gaphas.
It has diagram widgets allowing user placement and interaction, and appears to be quite active.
There's also a python-code generated diagram library (appropriately, and perhaps confusingly) called Diagrams, which you may be able to borrow from, though doesn't appear interactive.
Writing graphviz dot files is a good way to go. Google for graphviz and see http://code.google.com/p/pydot/ for a python wrapper.