I am coding a fun little text base game to get back into programming. Most of the code is in python but I'm only designing it for a dos console so I'm occasionally using dos commands via Pythons "os" module.
I want to be able to put a character to the console without "redrawing" the current screen line by line. I hoped there would be a command like "print []" but where it would not just create a new line, but instead let me specify exactly where on the screen I want to write a character or a string.
Scenario:
I print 3 options for the user to select. The first option has "*" by it to show that it is selected. If the user hits the down arrow key, the second option should now be selected. Instead of clearing the whole screen and re-printing all three options, but with the "*" now by the second option, I want to just "erase" the "*" by the first option, and "move" it to the second one, leaving everything else on the screen as it was.
2 2500 dwblas 626
Recognized Expert Contributor
A canvas widget, which is in every GUI is probably a good option here. Something kind of similar is a menu which you can look at and adapt. Note that button #1 is the only one that changes when any button is pressed. - from Tkinter import *
-
-
class MenuTest():
-
def __init__(self, top):
-
##--- always place in upper left corner ( +10+10 )
-
## size = 150x150 = minimum size so it's big enough to be seen
-
top.geometry("150x150+10+10" )
-
-
label1 = Label( top, text = "Test Menu" )
-
label1.pack()
-
-
label2 = Label( top, text = "" ) ## blank line = spacer
-
label2.pack()
-
-
self.button1_lit = StringVar()
-
self.button1_lit.set("Option 1")
-
option1 = Button(top, textvariable=self.button1_lit,
-
command=self.callback1, bg='blue', fg='white' )
-
option1.pack(fill=X, expand=1)
-
-
option2 = Button(top, text='Option 2',
-
command=self.callback2, bg='green', fg='white' )
-
option2.pack(fill=X, expand=1)
-
-
option3 = Button(top, text='Option 3 - No Exit',
-
command=self.callback3, bg='black', fg='white' )
-
option3.pack(fill=X, expand=1)
-
-
exit= Button(top, text='EXIT',
-
command=top.quit, bg='red', fg='white' )
-
exit.pack(fill=X, expand=1)
-
-
-
def callback1(self) :
-
print "Callback #1"
-
self.button1_lit.set("SELECTED")
-
-
def callback2(self) :
-
self.button1_lit.set("Button 1")
-
print "Callback #2"
-
-
def callback3(self) :
-
self.button1_lit.set("Button 1")
-
print "Callback #3"
-
-
##===============================================================
-
top = Tk()
-
MT=MenuTest(top)
-
-
top.mainloop()
Also consider using radio buttons. This example is from effbot's site http://effbot.org/tkinterbook/radiobutton.htm - from Tkinter import *
-
-
master = Tk()
-
master.geometry("100x50")
-
-
v = IntVar()
-
-
Radiobutton(master, text="One", variable=v, value=1).pack(anchor=W)
-
Radiobutton(master, text="Two", variable=v, value=2).pack(anchor=W)
-
-
mainloop()
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Derek_Bennett |
last post by:
I would like to find out how to write out messages to the Mozilla
JavaScript Console. This would allow me to have a client-side record
of execution which would be ideal in debugging end-user...
|
by: Mullin Yu |
last post by:
i want to build an application of both gui and batch interface by using
windows application project.
i check either passing any args or not. if no, then open the gui
application. if yes, use the...
|
by: Tiësto |
last post by:
Sometimes I have a string variable with many escaped characters. And when I
write
?MyString
in the Immediate window, the output is done with the \n \t and similar
characteres.
Is there any...
|
by: Bock |
last post by:
I was just told about Python. My searching and reading over the net
I was able to learn that Python can handle "foreign" characters via
Unicodes.
Can or does Python write unicode to the...
|
by: Eric |
last post by:
I have a master page, and want each derived page to have a separate script
associated with it. However, I'm not sure where to put the <script> tag. I
tried putting it into the Derived.aspx inside...
|
by: Abel Chan |
last post by:
Hi there,
I am trying to use ASP.NET to populate list of files with hyper link from a
specific directory. The following code works well but it populates the list
to the top of the web page. I...
|
by: Steven Prasil |
last post by:
When I run/debug a program with Console.out.write statements inside and the program
execution reaches this statement then a new console/command prompt window (this with black background)
is opened...
|
by: kj |
last post by:
How can a script send (non-fatal) warnings and other such messages
to Firefox's JavaScript console?
Thanks!
kj
--
NOTE: In my address everything before the first period is backwards;
and...
|
by: not_a_commie |
last post by:
How do you send an escape key to the console? I was trying to change
the color of the text in cmd.exe with something like this:
Console.Out.Write("\u001b[1;31m");
But that doesn't seem to have...
|
by: tshad |
last post by:
I am using VS 2005 and just built a simple application that opens an xml
file and I want to put the table names on the console.
But when I try to use Console.Write (or Console.Readline), I get an...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |