Repository navigation
Expand file tree
/
Copy pathSave_A_Dog_Loop.py
More file actions
94 lines (79 loc) · 4.42 KB
/
Copy pathSave_A_Dog_Loop.py
File metadata and controls
94 lines (79 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
🐾 Dog Rescue Donation Dialog
👤 Author: PJ (@pjprogrammers)
📄 License: MIT
🔗 GitHub Profile: https://github.com/pjprogrammers
🔗 GitHub Repo: https://github.com/pjprogrammers/python
📝 Description:
A simple interactive dialog using tkinter message boxes that prompts the user
to decide about saving a starving dog by donating $5. The dialog loops logically
until the user makes a conclusive choice.
⚙️ How It Works:
- The user is asked if they want to save a starving dog.
- If yes, asked if they want to donate $5.
- If no, they're asked multiple follow-ups about their choice with warnings.
- Uses loops to ensure the conversation continues until a clear decision is reached.
🎯 Purpose:
To demonstrate GUI dialog handling and control flow with loops in Python using tkinter,
while practicing good user interaction design.
"""
from tkinter import Tk, messagebox as mg
def dog_rescue_dialog():
"""
Controls the full dialog loop for dog rescue donation interaction.
"""
root = Tk()
root.withdraw() # Hide the main Tk window
while True:
# Step 1: Ask if user wants to save the dog
save = mg.askquestion(title="Notice!", message="There is a dog about to die of starvation.\nWould you like to save it?", icon='info')
if save == 'yes':
# Step 2: Ask if user wants to donate $5
donate = mg.askquestion(title="Donation", message="Would you like to donate $5 to feed it?")
if donate == 'yes':
mg.showinfo(title="Thank You", message="Thank you for your donation! 🐶❤️")
break # End conversation positively
else:
# Step 3: If user refuses to donate
want_die = mg.askquestion(title="Notice!", message="Do you want the dog to die?")
if want_die == 'yes':
confirm = mg.askokcancel(title="Warning", message="Your actions might take someone's life.")
if confirm:
mg.showinfo(title="Information", message="The dog has died. 🐾💔")
mg.askquestion(title="", message="Do you feel happy now?")
mg.showwarning(title="", message="You are evil.")
mg.showerror(title="Notice", message="You have obtained rewards for KILLING a dog.")
mg.showinfo(title="Rewards", message="You have successfully obtained a seat in hell.")
break # End conversation negatively
else:
# User changed mind at last moment
continue # Loop again to restart
else:
# User wants to save the dog after refusing donation
continue # Loop again to restart
else:
# User does not want to save dog initially
want_die = mg.askquestion(title="Notice!", message="Do you want the dog to die?")
if want_die == 'yes':
confirm = mg.askokcancel(title="Warning", message="Your actions might take someone's life.")
if confirm:
mg.showinfo(title="Information", message="The dog has died. 🐾💔")
mg.askquestion(title="", message="Do you feel happy now?")
mg.showwarning(title="", message="You are evil.")
mg.showerror(title="Notice", message="You have obtained rewards for KILLING a dog.")
mg.showinfo(title="Rewards", message="You have successfully obtained a seat in hell.")
break # End conversation negatively
else:
continue # Loop again to restart
else:
# User doesn't want dog to die and didn't want to save initially
# Ask about donating $5 anyway
donate_anyway = mg.askquestion(title="Notice", message="Then do you want to donate $5 to save it?")
if donate_anyway == 'yes':
mg.showinfo(title="Thank You", message="Thank you for your donation! 🐶❤️")
break
else:
continue # Loop again to restart
root.destroy() # Close the hidden root window
if __name__ == "__main__":
dog_rescue_dialog()