屏幕#
介绍#
屏幕方法控制 V5 大脑如何在触摸屏上显示文本、数字和图形,以及如何响应触摸输入。
默认情况下,打印到大脑的字体是等宽小号,它有 12 行 48 列。
大脑的绘图分辨率为 480 x 240 像素。

以下是所有方法的列表:
光标打印 — 放置并打印文本。
print— 在当前光标位置打印文本、数字或变量值。set_cursor— 将光标移动到指定的行和列。next_row— 将光标移动到下一行的第 1 列。clear_row— 清除一行文本。row— 返回要打印文本的行。column— 返回要打印文本的列。print_at— 在指定的 x 和 y 坐标处打印文本、数字或变量值。get_string_width— 使用当前字体返回字符串的像素宽度。get_string_height— 使用当前字体返回字符串的像素高度。clear_line— 清除一行文本。new_line— 将光标移到新行。
修改器——更改屏幕设置、颜色和绘制行为。
clear_screen— 清除屏幕上的所有绘图和文本。set_font— 设置打印文本的字体。set_pen_width— 设置绘制的线条和形状轮廓的粗细。set_pen_color— 设置文本、像素、线条和形状轮廓的颜色。set_fill_color— 设置绘制形状和打印文本背景的填充颜色。set_origin— 设置用于基于坐标的打印和绘图的原点。
绘制 — 在屏幕上添加图形。
draw_pixel— 在坐标处绘制一个像素。draw_line— 在两点之间画一条线。draw_rectangle— 绘制一个矩形。draw_circle— 画一个圆。render— 仅在调用时更新大脑的屏幕,显示文本和图形。set_clip_region— 限制图形和文本的显示位置。
获取器 — 检查触摸状态和触摸位置。
pressing— 返回屏幕是否被按下。x_position— 返回最后一次屏幕按下的 x 坐标。y_position— 返回最后一次屏幕按下的 y 坐标。
回调函数——响应屏幕上的触摸事件。
有关构建 Brain 以访问 screen 方法的信息,请参阅 Brain。
光标打印#
print#
print 在 Brain 屏幕上以当前光标位置和字体打印文本、数字或变量值。
用法:
brain.screen.print(text, sep, precision)
参数 |
描述 |
|---|---|
|
要打印的文本、数字或变量值。 |
|
可选。要在值之间插入的字符串。必须将其写成关键字参数(sep=)。默认值为 |
|
可选。打印简单数字时显示的小数位数。必须以关键字参数的形式指定( |
# Print on the Brain's screen
brain.screen.print("Hello, Robot!")

set_cursor#
set_cursor moves the cursor to a specific row and column on the Brain screen. The next print call will start printing at that location. How many rows and columns can comfortably fit depends on the selected font. With the default monospaced medium font, up to 8 rows and 13 columns can be displayed clearly. Text placed beyond this range may be cut off or become difficult to read.
Monospaced fonts have characters that are all the same width, making text placement consistent. In contrast, proportional fonts vary in character width, so some letters take up more space than others. However, regardless of which type is used, set_cursor positions the cursor based on row and column size, not font style. The font size can be adjusted using the set_font.
用法:
brain.screen.set_cursor(row, column)
参数 |
描述 |
|---|---|
|
要将光标移动到的行。 |
|
要将光标移动到的列。 |
# Display text starting at Row 3 Column 12
brain.screen.set_cursor(3, 12)
brain.screen.print("Row 3, Column 12")

next_row#
next_row 将光标移动到下一行。
用法:
brain.screen.next_row()
参数 |
描述 |
|---|---|
此方法没有参数。 |
# Print two lines of text on the Brain's screen
brain.screen.print("Line 1")
brain.screen.next_row()
brain.screen.print("Line 2")

clear_row#
clear_row 清除大脑屏幕上的一行文本。
用法:
brain.screen.clear_row(row, color)
参数 |
描述 |
|---|---|
|
可选。要清除的行。默认值为当前光标所在行。 |
|
可选。有效的颜色、十六进制值或网页字符串。 |
# Only keep the text on row 1
brain.screen.print("This text stays")
brain.screen.next_row
brain.screen.print("This text disappears")
wait(3, SECONDS)
brain.screen.clear_row()
row#
row 条返回将以整数形式打印文本的行。
用法:
brain.screen.row()
参数 |
描述 |
|---|---|
此方法没有参数。 |
# Display the cursor's current row
brain.screen.set_cursor(3, 2)
brain.screen.print(brain.screen.row())

column#
column 返回文本将以整数形式打印的列。
用法:
brain.screen.column()
参数 |
描述 |
|---|---|
此方法没有参数。 |
# Display the cursor's current column
brain.screen.set_cursor(3, 15)
brain.screen.print(brain.screen.column())

print_at#
print_at 在 Brain 屏幕上的特定 x 和 y 坐标处,使用当前的 font 和 origin 打印文本、数字或变量值。
用法:
brain.screen.print_at(text, x, y, sep, precision, opaque)
参数 |
描述 |
|---|---|
|
要打印的文本、数字或变量值。 |
|
要打印的 x 坐标作为关键字参数( |
|
要打印的 y 坐标作为关键字参数( |
|
可选。要在值之间插入的字符串。必须将其写成关键字参数(sep=)。默认值为 |
|
可选。打印简单数字时显示的小数位数。必须以关键字参数的形式指定( |
|
可选。一个布尔值,指示文本是否应清除背景像素。默认值为 |
# Display text at the center of the screen
brain.screen.print_at("Center", x=220, y=120)

get_string_width#
get_string_width 返回字符串的宽度(以像素为单位),以整数形式表示,使用当前的 font。
Usage:
brain.screen.get_string_width(string)
参数 |
描述 |
|---|---|
|
待测量的绳子。 |
get_string_height#
get_string_height 返回字符串的高度(以像素为单位),使用当前的 font。
Usage:
brain.screen.get_string_height(string)
参数 |
描述 |
|---|---|
|
待测量的绳子。 |
clear_line#
clear_line 清除当前行的文本。
Usage:
brain.screen.clear_line()
参数 |
描述 |
|---|---|
此方法没有参数。 |
new_line#
new_line 将光标移动到 Brain 屏幕上下一行的第 1 列。
用法:
brain.screen.new_line()
参数 |
描述 |
|---|---|
此方法没有参数。 |
变异体#
clear_screen#
clear_screen 清除大脑屏幕上的所有图形和文本。
用法:
brain.screen.clear_screen(color)
参数 |
描述 |
|---|---|
|
Optional. A valid color option:
|
# Print VEXcode on the screen
brain.screen.print("VEXcode")
wait(2, SECONDS)
# Clear screen to black
brain.screen.clear_screen()
# Print VEXcode on the screen
brain.screen.print("VEXcode")
# Clear screen to blue using predefined color
brain.screen.clear_screen(Color.BLUE)

set_font#
set_font 设置用于在大脑屏幕上显示文本的字体。此字体将应用于此方法运行后打印的所有文本。
用法:
brain.screen.set_font(font)
参数 |
描述 |
|---|---|
|
以下是一个有效的字体选项。 |
|
|
|
|---|---|---|
|
|
|
|
|
|
|
# Set the font type to MONO40
brain.screen.set_font(FontType.MONO40)
brain.screen.print("VEX")

set_pen_width#
set_pen_width 设置绘制线条和形状轮廓的粗细。
用法:
brain.screen.set_pen_width(value)
参数 |
描述 |
|---|---|
|
笔的宽度,以像素为单位,范围从 0 到 32。 |
# Draw a rectangle with a pen width of 10
brain.screen.set_pen_width(10)
brain.screen.draw_rectangle(50, 50, 130, 60)

set_pen_color#
set_pen_color 设置文本、像素、线条和形状轮廓的颜色。
用法:
brain.screen.set_pen_color(color)
参数 |
描述 |
|---|---|
|
要使用的笔和字体颜色。选项包括:
|
# Draw a rectangle with orange borders
brain.screen.set_pen_color(Color.ORANGE)
brain.screen.draw_rectangle(50, 50, 130, 60)

set_fill_color#
set_fill_color 设置绘制形状时使用的填充颜色。
用法:
brain.screen.set_fill_color(color)
参数 |
描述 |
|---|---|
|
要使用的填充颜色。选项包括:
|
# Draw a purple rectangle
brain.screen.set_fill_color(Color.PURPLE)
brain.screen.draw_rectangle(50, 130, 100, 60)

set_origin#
set_origin 设置 Brain 屏幕上用于绘图和基于坐标的打印的原点。默认情况下,原点位于屏幕左上角。
用法:
brain.screen.set_origin(x, y)
参数 |
描述 |
|---|---|
|
要设置的原点 x 坐标,范围从 0 到 479。 |
|
设置为原点的 y 坐标,范围从 0 到 239。 |
画#
draw_pixel#
draw_pixel 使用当前画笔颜色在选定的 x 和 y 坐标处绘制一个像素。
用法:
brain.screen.draw_pixel(x, y)
参数 |
描述 |
|---|---|
|
绘制像素的 x 坐标,范围从 0 到 479,以屏幕原点为参考。 |
|
绘制像素的 y 坐标,范围从 0 到 239,以屏幕原点为参考。 |
# Draw the pixels marking the corners of a square
brain.screen.draw_pixel(250, 100)
brain.screen.draw_pixel(275, 100)
brain.screen.draw_pixel(250, 125)
brain.screen.draw_pixel(275, 125)
![]()
draw_line#
draw_line 使用当前笔宽和笔色,从第一个屏幕坐标到第二个屏幕坐标绘制一条线。
用法:
brain.screen.draw_line(start_x, start_y, end_x, end_y)
参数 |
描述 |
|---|---|
|
行首的 x 坐标(以像素为单位),范围从 0 到 479,参考屏幕原点。 |
|
行首的 y 坐标(以像素为单位),范围从 0 到 239,参考屏幕原点。 |
|
行尾的 x 坐标(以像素为单位),范围从 0 到 479,参考屏幕原点。 |
|
行尾的 y 坐标(以像素为单位),范围从 0 到 239,以屏幕原点为参考。 |
# Draw a line from the top left to bottom right of the screen
brain.screen.draw_line(0, 0, 479, 239)

draw_rectangle#
draw_rectangle 使用当前画笔宽度、画笔颜色和填充颜色绘制矩形,除非使用可选的 color 参数。
用法:
brain.screen.draw_rectangle(x, y, width, height, color)
参数 |
描述 |
|---|---|
|
矩形左上角的 x 坐标(像素),取值范围为 0 到 479。 |
|
矩形左上角的 y 坐标(像素),取值范围为 0 到 239。 |
|
矩形的宽度。 |
|
矩形的高度。 |
|
Optional. A valid color option:
|
# Draw a rectangle on the screen
brain.screen.draw_rectangle(50, 50, 130, 60)

draw_circle#
draw_circle 使用当前的画笔宽度、画笔颜色和填充颜色绘制一个圆,除非使用了可选的 color 参数。
用法:
brain.screen.draw_circle(x, y, radius, color)
参数 |
描述 |
|---|---|
|
圆心的 x 坐标(以像素为单位),范围从 0 到 479,参考屏幕原点。 |
|
圆心的 y 坐标(以像素为单位),范围从 0 到 239,参考屏幕原点。 |
|
圆的半径,以像素为单位。 |
|
可选。要使用的填充颜色。选项包括:
|
# Draw a circle on the screen
brain.screen.draw_circle(120, 120, 40)

render#
render 为大脑屏幕启用双缓冲。调用后,任何绘图命令(例如文本、形状或图像)都不会立即显示在项目的其余部分。相反,更新内容只有在再次使用 render 时才会显示。这使得屏幕更新更加流畅和可控,但也意味着在 render 之前,屏幕内容将不可见。
用法:
brain.screen.render()
参数 |
描述 |
|---|---|
此方法没有参数。 |
# Render text after moving
brain.screen.render()
brain.screen.print("Render later...")
drivetrain.drive_for(FORWARD, 100, MM)
drivetrain.turn_for(RIGHT, 90, DEGREES)
brain.screen.render()
set_clip_region#
set_clip_region 定义了屏幕上的一个矩形区域,所有图形和文本都将限制在该区域内。该区域之外的任何内容都不会显示。
用法:
brain.screen.set_clip_region(x, y, width, height)
参数 |
描述 |
|---|---|
|
矩形左上角的 x 坐标,以屏幕原点为参考。 |
|
矩形左上角的 y 坐标,以屏幕原点为参考。 |
|
矩形的宽度。 |
|
矩形的高度。 |
# Restrict text and drawings to a specific region
brain.screen.set_clip_region(0, 0, 120, 120)
brain.screen.draw_rectangle(60, 60, 100, 100, Color.RED)
brain.screen.print_at("Cut off!", x=60, y=60)

触碰#
pressing#
pressing 返回一个布尔值,指示当前是否正在按下大脑屏幕。
True- 屏幕被按下。False- 屏幕未被按下。
用法:
brain.screen.pressing()
参数 |
描述 |
|---|---|
此方法没有参数。 |
# Change the screen's color after it's pressed
while not brain.screen.pressing():
wait(5, MSEC)
brain.screen.set_fill_color(Color.GREEN)
brain.screen.draw_rectangle(0, 0, 479, 239)
# Display different messages after the screen is pressed
while not brain.screen.pressing():
wait(5, MSEC)
brain.screen.print("First message!")
brain.screen.next_row()
# Lift finger to press the screen again
while brain.screen.pressing():
wait(5, MSEC)
while not brain.screen.pressing():
wait(5, MSEC)
brain.screen.print("Second message!")
brain.screen.next_row()
x_position#
x_position 返回上次屏幕按下的 x 坐标,取值范围为 0(左)到 479(右)的整数。
用法:
brain.screen.x_position()
参数 |
描述 |
|---|---|
此方法没有参数。 |
# Display a circle where the screen is pressed
while not brain.screen.pressing():
wait(5, MSEC)
brain.screen.set_fill_color(Color.WHITE)
brain.screen.draw_circle(brain.screen.x_position(), brain.screen.y_position(), 20)
y_position#
y_position 返回上次屏幕按下的 y 坐标,数值为 0(上)到 239(下)之间的整数。
用法:
brain.screen.y_position()
参数 |
描述 |
|---|---|
此方法没有参数。 |
# Display a circle where the screen is pressed
while not brain.screen.pressing():
wait(5, MSEC)
brain.screen.set_fill_color(Color.WHITE)
brain.screen.draw_circle(brain.screen.x_position(), brain.screen.y_position(), 20)
回调函数#
pressed#
pressed 注册一个在按下大脑屏幕时要调用的函数。
用法:
brain.screen.pressed(callback, arg)
参数 |
描述 |
|---|---|
|
一个先前定义的函数,当按下大脑屏幕时执行。 |
|
def my_function():
brain.screen.print("Screen pressed")
# Call my_function whenever the Brain screen is pressed
brain.screen.pressed(my_function)
released#
released 注册一个在屏幕释放(触摸移除)时要调用的函数。
用法:
brain.screen.released(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的 函数 在大脑屏幕释放时执行。 |
|
def my_function():
brain.screen.print("Screen released")
# Call my_function whenever the Brain screen is released
brain.screen.released(my_function)









