Κονσόλα#
Εισαγωγή#
Η Κονσόλα VEXcode V5 εμφανίζεται στο παράθυρο Monitor (Οθόνη) μέσα στο VEXcode. Οι μέθοδοι κονσόλας μπορούν να εμφανίσουν κείμενο, αριθμούς και τιμές μεταβλητών ενώ εκτελείται ένα έργο. Μπορούν επίσης να διαγράψουν την Κονσόλα, να διαβάσουν την είσοδο χρήστη και να ορίσουν το χρώμα του κειμένου που εκτυπώνεται μετά την αλλαγή του χρώματος.
Όταν χρησιμοποιείτε τον κώδικα VS, η έξοδος της κονσόλας που βασίζεται σε κείμενο εμφανίζεται στο τερματικό αντί για την κονσόλα VEXcode.
Σημείωση: Όταν χρησιμοποιείτε την Κονσόλα VEXcode, πρέπει να συνδεθείτε στη Σειριακή Θύρα της Κονσόλας προτού εκτυπωθεί οποιαδήποτε έξοδος στην Κονσόλα.
Παρακάτω είναι μια λίστα με όλες τις μεθόδους:
Ενέργειες — Εξαγωγή κειμένου ή εκκαθάριση της Κονσόλας.
print— Displays text, numbers, or variable values in the Console or terminal.clear_console— Clears all rows in the Console.
Getter — Ανάγνωση εισόδου χρήστη.
input— Displays an optional prompt string, waits for user input, and returns the response as text.
Mutator — Μορφοποίηση εκτυπωμένου κειμένου.
set_console_text_color— Sets the color used for text printed in the Console.
Ενέργειες#
print#
print displays text, numbers, or variable values in the Console. In VS Code, print displays output in the terminal.
Χρησιμοποιήστε προσαρμοσμένη μορφοποίηση συμβολοσειράς όταν θέλετε ένα εκτυπωμένο μήνυμα να περιλαμβάνει τιμές από το έργο σας, όπως μια βαθμολογία, ένα χρονόμετρο ή μια ένδειξη αισθητήρα. Ανατρέξτε στη σελίδα Μορφοποίηση συμβολοσειράς για περισσότερες πληροφορίες.
By default, each print() statement ends with \n, which stands for a new line. This moves the cursor to the next line after the value is printed. The optional end parameter changes what is added after the printed value.
Usage:
print(value, end=“\n”)
Παράμετρος |
Περιγραφή |
|---|---|
|
Το κείμενο, ο αριθμός ή η τιμή μεταβλητής που θα εμφανίζεται στην Κονσόλα ή στο τερματικό. |
|
Optional. The text added after |
# Display two messages on separate lines
print("Hello, robot!")
print("This prints on the next line.")

# Display two messages on the same line
print("Hello,", end=" ")
print("robot!")

# Print three colors on one line, separated by commas
colors = ["Red", "Green", "Blue"]
for color in colors:
print(color, end=", ")

Ακολουθίες διαφυγής#
Escape sequences are short codes that can be printed with print to change how text appears in the Console.
Most projects should use set_console_text_color to change text color and clear_console to clear the Console. Escape sequences are useful when you want to do those things directly inside a print statement.
To change the text color, print \033 followed by a color code.
Χρώμα |
Ακολουθία διαφυγής |
|---|---|
Κόκκινος |
|
Πράσινος |
|
Μπλε |
|
Μαύρος |
|
Λευκό |
|
Κίτρινος |
|
Πορτοκάλι |
|
Μωβ |
|
Κυανό |
|
Διαφανής |
|
# Print VEXcode in red
print("\033[31mVEXcode")
# Print text in different colors
print("Default text color")
print("\033[31m")
print("Red text color")

To clear the entire Console with an escape sequence, print \033[2J. This also moves the cursor back to row 1.
# Clear the Console after two seconds
print("VEXcode")
wait(2, SECONDS)
print("\033[2J")
clear_console#
clear_console clears all rows from the Console.
Usage:
clear_console()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Display text, then clear it after two seconds
print("This will disappear...")
wait(2, SECONDS)
clear_console()
Λήπτης#
input#
input displays an optional prompt string, waits for the user to enter a response, then returns that response as text.
The project pauses at input() until a response is entered in the Console. In VS Code, the response is entered in the terminal.
The value returned by input() is always text. To use the response as a number, convert it first with int() or float().
Usage:
input(prompt)
Παράμετρος |
Περιγραφή |
|---|---|
|
Προαιρετικό. Μια συμβολοσειρά που θα εμφανίζεται στην Κονσόλα ή στο τερματικό πριν από την αναμονή για απάντηση. Εάν δεν περιλαμβάνεται καμία προτροπή, δεν εμφανίζεται κανένα μήνυμα πριν από την αναμονή. |
# Ask for a name, then print a greeting
answer = input("What's your name?")
print("Hello, " + answer)

# Ask for a number, then use it in math
answer = input("Enter a number:")
number = float(answer)
print(number + 1)

Μεταλλακτής#
set_console_text_color#
set_console_text_color sets the color used for text printed in the Console after this method is used. At the start of a project, the Console text color is set to BLUE.
Αυτή η μέθοδος αλλάζει το χρώμα κειμένου στην κονσόλα VEXcode. Στο VS Code, η υποστήριξη χρωμάτων τερματικού μπορεί να διαφέρει ανά τερματικό.
Usage:
set_console_text_color(color)
Παράμετρος |
Περιγραφή |
|---|---|
|
The color to use for text printed in the Console:
|
# Print text in different colors
print("Default text color")
set_console_text_color(Color.RED)
print("Red text color")
