Sfoglia il codice sorgente

Einfügen des Neustart-Buttons, um das Spiel von vorne beginnen zu können,
ohne das Fenster schließen zu müssen

Kristin 7 anni fa
parent
commit
071132d2f4
1 ha cambiato i file con 17 aggiunte e 8 eliminazioni
  1. 17 8
      pingpong.py

+ 17 - 8
pingpong.py

1
-#Programmierung 2 - Ping Pong Spiel
1
+# Programmierung 2 - Ping Pong Spiel
2
 # Willi Schlegel, Francine Theil, Kristin Weber
2
 # Willi Schlegel, Francine Theil, Kristin Weber
3
 # letzte Aenderung: 20.07.2017
3
 # letzte Aenderung: 20.07.2017
4
 
4
 
8
 import random
8
 import random
9
 import time
9
 import time
10
 from Tkinter import *
10
 from Tkinter import *
11
+import os
12
+import sys
13
+
14
+
15
+#----------------------------------------------------------------
16
+# Funktion für den Neustart des Programms
17
+
18
+def restart_program():
19
+    python = sys.executable
20
+    os.execl(python, python, * sys.argv)
11
 
21
 
12
 
22
 
13
 #----------------------------------------------------------------
23
 #----------------------------------------------------------------
98
 #----------------------------------------------------------------------------
108
 #----------------------------------------------------------------------------
99
 # Spieloberflaeche
109
 # Spieloberflaeche
100
 
110
 
111
+
101
 tk = Tk()
112
 tk = Tk()
102
 tk.title("Superfantastisches Ping-Pong-Spiel")
113
 tk.title("Superfantastisches Ping-Pong-Spiel")
103
 canvas = Canvas(tk, width=500, height=400, bd=3, bg='pink')
114
 canvas = Canvas(tk, width=500, height=400, bd=3, bg='pink')
109
 
120
 
110
 
121
 
111
 
122
 
112
-exit_button = Button(tk, text="Spiel starten", command=tk.quit)
113
-exit_button.pack()
123
+start_button = Button(tk, text="Spiel starten", command=tk.quit)
124
+start_button.pack()
125
+neustart_button = Button(tk, text="Neues Spiel", command=restart_program)
126
+neustart_button.pack()
127
+
114
 tk.mainloop()
128
 tk.mainloop()
115
 
129
 
116
 def button_action():
130
 def button_action():
138
     tk.update()
152
     tk.update()
139
     time.sleep(0.01)
153
     time.sleep(0.01)
140
 
154
 
141
-#button_action()
142
-#tk.mainloop()
143
 
155
 
144
-if __name__ == "__main__":
145
-    app = Ball()
146
-    app.mainloop()