Jake
Jake

Reputation: 1

Killing a Python program using ctrl C

I have an assignment in school which i can't get around and i'm stuck with.

the assignment is to build a program that infinitly spews out random numbers in a EasyGUI messagebox ( Yeah i know EasyGUI is old xD )

this is my source code:

import easygui

while True:
    easygui.msgbox(random.randint(-100, 100))

The problem is that when i run this i can't get out of it. I should be allowed to use ctrl+C but that doesn't work. Am i missing something?

Thank you in advance!

Upvotes: 0

Views: 123

Answers (2)

Haoyang Song
Haoyang Song

Reputation: 162

your problem is that you can't use ctrl-c when using easygui, you can use ctrl-c when using the idle for example you can do

for i in range(1, 10000000000000000000000000000000000000000000000):
    print(i)

that will work, it won't on easygui, since i spews out frames one by one.its to slow

Upvotes: 1

Padraic Cunningham
Padraic Cunningham

Reputation: 180532

using signalhandlers does not seem to be a trivial task when it comes to easygui, if you can work with quitting when x is pressed you can do the following:

while True:
    e = easygui.msgbox(random.randint(-100, 100))
    if e is None:
        break

e will either be a string "OK" if you press ok or None if x is pressed so it is probably the simplest way to quit and end the loop.

Upvotes: 0

Related Questions