当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Python turtle.window_width()用法及代码示例

turtle 模块以面向对象和面向过程的方式提供 turtle 图形基元。由于它使用Tkinter作为基础图形,因此需要安装有Tk支持的Python版本。

turtle .window_width()

此函数用于返回 turtle 窗口的宽度。它不需要任何参数。

用法:

turtle.window_width()

下面是上述方法的实现示例:

Python3



# import package 
import turtle 
  
# get turtle window width 
print(turtle.window_width()) 
  
# make screen object 
# then set size and color 
sc = turtle.Screen() 
sc.setup(300,300) 
sc.bgcolor("green") 
  
# get turtle window width 
print(turtle.window_width()) 
  
# loops for pass time 
for i in range(5000):
  for j in range(5000):
    pass
  
# set size and color again 
sc.setup(500,400) 
sc.bgcolor("red") 
  
# get turtle window width 
print(turtle.window_width())

输出:

768
300
500

相关用法


注:本文由纯净天空筛选整理自deepanshu_rustagi大神的英文原创作品 turtle.window_width() function in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。