473,466 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can I write (put) a character in a specific spot on a dos console?

1 New Member
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.
Jan 1 '11 #1
2 2500
Mariostg
332 Contributor
Did you look at python curses
Jan 12 '11 #2
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.
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2.  
  3. class MenuTest():
  4.     def __init__(self, top):
  5.         ##---  always place in upper left corner ( +10+10 )
  6.         ##     size = 150x150 = minimum size so it's big enough to be seen
  7.         top.geometry("150x150+10+10" )
  8.  
  9.         label1 = Label( top, text = "Test Menu" )
  10.         label1.pack()
  11.  
  12.         label2 = Label( top, text = "" )          ## blank line = spacer
  13.         label2.pack()
  14.  
  15.         self.button1_lit = StringVar()
  16.         self.button1_lit.set("Option 1")
  17.         option1 = Button(top, textvariable=self.button1_lit,
  18.                   command=self.callback1, bg='blue', fg='white' )
  19.         option1.pack(fill=X, expand=1)
  20.  
  21.         option2 = Button(top, text='Option 2',
  22.                   command=self.callback2, bg='green', fg='white' )
  23.         option2.pack(fill=X, expand=1)
  24.  
  25.         option3 = Button(top, text='Option 3 - No Exit',
  26.                   command=self.callback3, bg='black', fg='white' )
  27.         option3.pack(fill=X, expand=1)
  28.  
  29.         exit=  Button(top, text='EXIT',
  30.                   command=top.quit, bg='red', fg='white' )
  31.         exit.pack(fill=X, expand=1)
  32.  
  33.  
  34.     def callback1(self) :
  35.         print "Callback #1"
  36.         self.button1_lit.set("SELECTED")
  37.  
  38.     def callback2(self) :
  39.         self.button1_lit.set("Button 1")
  40.         print "Callback #2"
  41.  
  42.     def callback3(self) :
  43.         self.button1_lit.set("Button 1")
  44.         print "Callback #3"
  45.  
  46. ##===============================================================
  47. top = Tk()
  48. MT=MenuTest(top)
  49.  
  50. top.mainloop() 
Also consider using radio buttons. This example is from effbot's site http://effbot.org/tkinterbook/radiobutton.htm
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2.  
  3. master = Tk()
  4. master.geometry("100x50")
  5.  
  6. v = IntVar()
  7.  
  8. Radiobutton(master, text="One", variable=v, value=1).pack(anchor=W)
  9. Radiobutton(master, text="Two", variable=v, value=2).pack(anchor=W)
  10.  
  11. mainloop() 
Jan 12 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
5
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...
2
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...
9
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...
0
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...
6
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...
1
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...
3
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...
1
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...
2
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
tracyyun
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...
0
agi2029
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.