Python Turtle : Handling two successive screens for two successive event-listener driven game Functions

I’m new to Python and trying out Turtle through Tutorials. This question turned out to be verbose, my bad.

I have designed 2 Games handled by 2 Functions (in a separate module) which are called from MAIN –
F1 : Plays an Etch a Sketch Game where user inputs are used to move the Turtle to draw
F2 : Plays a Turtle Race where 5 Turtles (I have used a list to handle 5 Objects) move at randomized paces to see who wins.

The ISSUE : I tried mainloop() but that didn’t solve it, unless I used it wrong.

  • The games are fine but I have a problem with the Screen when the Games are running one after the other, and went through numerous Questions before posting.
  • I have initialized a create_screen() method in a separate config.py file which I import in each FN to create a screen. I then use exitonclick() to end the display. (Should I use Global – Just wanted to see how to make it work WITHOUT Global)
  • The Games work fine individually on the first iteration but I have a loop in MAIN where user can choose games multiple times. On the second iteration, the screen pops up but I don’t see the Turtles and when I click I get Turtle Terminator error.
  • I need FN1 to stop listening and the ask user if he wants FN2, then move to FN2 and I can’t seem to get that done without exitonclick() on FN1. How can I keep the screen alive, displayed, ready for FN2 ? It’s the only reason I am using Screen on config file and creating with FNs. I’m sure there is a way, I just don’t know it yet.

Solutions I have checked indicate the Turtle.RUNNING = True Flag which can be changed, but what is a better way to implement this without changing a Class Variable (or using Global) ? If someone can point me to the some sources (other than TURTLE DOCS) for Screen and Event Listeners to solve this, I’ll do the learning myself !

Code Skeleton : I’m loading config.py into FN Module and the Game Functions from MAIN

# Module : config.py

from turtle import Turtle, Screen

squad = []
for i in range(0, 5):  # List of Turtle Objects available to all Modules
    raphael = Turtle()
    raphael.speed(0)
    squad.append(raphael)

def create_screen():
    """Creates and Returns a screen Object"""
    screen = Screen()
    screen.screensize(400, 400)
    screen.colormode(255)
    return screen
# Module : gamefunction.py

from config import squad, create_screen

def etch_sketch_game():
    """Plays the Etch a Sketch Game"""

    screen_fn = create_screen()

    def forwards():  # Other FNs designed but not included for this Question
        squad[0].fd(30)

    screen_fn.listen()
    screen_fn.onkey(key="w", fun=forwards)
    screen_fn.exitonclick()


def turtle_race(): # Only adde
    """Plays the Turtle Race Game"""

    screen_fn = create_screen()

    squad[0].setpos(-200, 30)
    squad[1].setpos(-200, 20)
    squad[2].setpos(-200, 0)
    squad[3].setpos(-200, -20)
    squad[4].setpos(-200, -30)

    def forwards():  # Other FNs designed but not included for this Question
        squad[0].fd(30)

    screen_fn.onkey(key="w", fun=forwards)
    screen.exitonclick()

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật