當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python turtle.bye()用法及代碼示例

turtle 模塊以麵向對象和麵向過程的方式提供 turtle 圖形基元。由於它使用tkinter作為基礎圖形,因此需要安裝有Tk支持的Python版本。

turtle .bye()

此函數用於關閉龜圖形窗口。不需要任何參數。

用法:turtle.bye()
參數:None
Returns:Nothing

下麵是上述方法的實現和一些示例:

範例1:



# import package 
import turtle  
  
# set turtle speed to  
# slowest for better 
# understandings 
  
turtle.speed(1) 
# motion 
  
turtle.forward(200) 
# use bye() method to  
# shut the window 
turtle.bye()

輸出:

範例2:

# import package 
import turtle  
  
  
# set drawing turtle speed 
turtle.speed(10) 
  
# loop for pattern 
for i in range(12):
  turtle.circle(50) 
  turtle.right(30) 
  
# As simply use of bye() here will shut the  
# turtle graphics window too fast so use  
# loops to pass the time 
for i in range(2000):
  for j in range(500):
    pass
  
# shut the turtle graphics window 
turtle.bye()

輸出:





注:本文由純淨天空篩選整理自deepanshu_rustagi大神的英文原創作品 Python – turtle.bye()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。