瀏覽代碼

Menueoptimierung und Eingabe des Namens definiert

Kristin 7 年之前
父節點
當前提交
50f107a9d6
共有 1 個文件被更改,包括 33 次插入12 次删除
  1. 33 12
      pingpong.py

+ 33 - 12
pingpong.py

13
 
13
 
14
 
14
 
15
 #----------------------------------------------------------------
15
 #----------------------------------------------------------------
16
-# Funktion für den Neustart des Programms
16
+# Funktion fuer den Neustart des Programms
17
 
17
 
18
 def restart_program():
18
 def restart_program():
19
     python = sys.executable
19
     python = sys.executable
119
 ball = Ball(canvas, 'white', 25, paddle)
119
 ball = Ball(canvas, 'white', 25, paddle)
120
 
120
 
121
 
121
 
122
-
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)
122
 neustart_button = Button(tk, text="Neues Spiel", command=restart_program)
126
 neustart_button.pack()
123
 neustart_button.pack()
124
+start_button = Button(tk, text="Spiel starten", command=tk.quit)
125
+start_button.pack()
126
+exit_button = Button(tk, text='Quit', command=tk.destroy)
127
+exit_button.pack()
128
+
127
 
129
 
128
 tk.mainloop()
130
 tk.mainloop()
129
 
131
 
131
     anweisungs_label.config()
133
     anweisungs_label.config()
132
 
134
 
133
 
135
 
136
+#-------------------------------------------------------------------------
137
+# Namenseingabe
138
+
139
+def show_entry_fields():
140
+   e1 = Entry(tk)
141
+   print("Name: %s" % (e1.get()))
142
+
143
+
144
+def name_eingabe():
145
+   tk = Tk()
146
+   Label(tk, text="Name").grid(row=0)
147
+
148
+   e1 = Entry(tk)
149
+
150
+   e1.grid(row=0, column=1)
151
+
152
+   Button(tk, text='Show', command=show_entry_fields).grid(row=3, column=0, sticky=W, pady=4)
153
+
154
+   print("Name: %s" % (e1.get()))
155
+
156
+   mainloop()
157
+
158
+
134
 #--------------------------------------------------------------------------
159
 #--------------------------------------------------------------------------
135
 # Schleife fuer das fortlaufende Bewegen des Balles
160
 # Schleife fuer das fortlaufende Bewegen des Balles
136
 
161
 
138
 
163
 
139
     ball.draw()
164
     ball.draw()
140
     paddle.draw()
165
     paddle.draw()
141
-    canvas.itemconfig(label, text="Highscore: "+str(ball.score))
166
+    canvas.itemconfig(label, text="Punktestand: "+str(ball.score))
142
     tk.update_idletasks()
167
     tk.update_idletasks()
143
     tk.update()
168
     tk.update()
144
     time.sleep(0.01)
169
     time.sleep(0.01)
145
 
170
 
146
-while ball.hit_bottom == True:
171
+if ball.hit_bottom == True:
147
 
172
 
148
-    ball.draw()
149
-    paddle.draw()
150
-    canvas.itemconfig(label, text="Highscore: "+str(0))
151
-    tk.update_idletasks()
152
-    tk.update()
153
-    time.sleep(0.01)
173
+    name_eingabe()
154
 
174
 
175
+#------------------------------------------------------------------------------------------------------------------
155
 
176