October 31st, 2012, 12:40 AM
Program w/ text that can be highlighted
i just started python and am writing an error detection program - this program will present sentences to users and ask them to indicate errors - i would like to allow the users to click to highlight the error(s) in a sentence, move to the next sentence and repeat - whatever is highlighted will be copied and coded to a text file - so far, i haven't been able to find out how to create/code highlightable text, or if this is possible in python- if anyone knows how to do this it'd be appreciated -
October 31st, 2012, 01:34 AM
First off, is this a console program, or a GUI program using a toolkit such as Tkinter? If the latter, it should be just a matter of setting the font properties for the highlighted section.
If it is a console program, then things are a bit trickier, and will depend on the operating system you are running under. If you are using a Unix type system such as Linux or MacOS X, you should be able to use the curses library. You'd need to read the documentation on it to work out how to set the colors. Under Windows, you can use the Python for Windows Extensions, I think, though I'm not certain how it would work; again, the documentation is the key.
October 31st, 2012, 02:31 AM
thanks for the steer - it's going to be a console program, the lab i'm in is being refurbished (i'm assuming windows but should probably ask) - i built something similar on matlab, then started on perl, now they want everyone to switch to python - python seems pretty friendly but i didn't know where to look - thanks again -
October 31st, 2012, 10:36 AM
[/code] are essential for python code and Makefiles!
October 31st, 2012, 02:59 PM
Then curses is your friend, but keep in mind that the highlighting, etc. will have to be done using the keyboard. There is no clicking to highlight or dragging/dropping with the mouse on the console. A particular terminal emulator may provide some mouse functionality to allow you to implement those, but (1) I don't know of any that do, (2) the protocol would be completely terminal-specific and nonportable if it did, and (3) curses will not help you here. If you're not okay with a keyboard-driven interface, I'd ditch the console for your interface and go with a GUI.
Originally Posted by happer55
October 31st, 2012, 03:37 PM
Thanks to all, you saved me a lot of time. I'll go for a GUI, but this may get shot down (might confound the error detection task). I'm sure I'll have other problems, thanks again.
October 31st, 2012, 04:00 PM