Browse Source

Schreiben von Name und Punktzahl in eine Highscore-Liste

Kristin 7 years ago
parent
commit
88b33e36e0
1 changed files with 20 additions and 14 deletions
  1. 20 14
      pingpong.py

+ 20 - 14
pingpong.py

@@ -1,3 +1,4 @@
1
+
1 2
 # Programmierung 2 - Ping Pong Spiel
2 3
 # Willi Schlegel, Francine Theil, Kristin Weber
3 4
 # letzte Aenderung: 21.07.2017
@@ -123,7 +124,7 @@ neustart_button = Button(tk, text="Neues Spiel", command=restart_program)
123 124
 neustart_button.pack()
124 125
 start_button = Button(tk, text="Spiel starten", command=tk.quit)
125 126
 start_button.pack()
126
-exit_button = Button(tk, text='Quit', command=tk.destroy)
127
+exit_button = Button(tk, text='Spiel beenden', command=tk.destroy)
127 128
 exit_button.pack()
128 129
 
129 130
 
@@ -140,16 +141,28 @@ def button_action():
140 141
 def anzeige():
141 142
 
142 143
    def show_entry_fields():
143
-      print("Name: %s" % (e1.get()))
144 144
 
145
-   master = Tk()
146
-   Label(master, text="Name").grid(row=0)
145
+      a = e1.get()     
146
+      print("Name: ", a)
147 147
 
148
-   e1 = Entry(master)
148
+      tupel = [a, str(ball.score)]
149
+      tupel = str(tupel)
150
+      hsin = open("highscore.txt", "a")
151
+      hsout = hsin.write(tupel + "\n")
152
+      hsin.close
149 153
 
150
-   e1.grid(row=0, column=1)
154
+      master = Tk()
155
+      master.title("Highscore-Liste")
156
+      canvas = Canvas(master, width=200, height=400, bd=2, bg='white')
157
+      canvas.pack()
158
+      mainloop()
151 159
 
152
-   Button(master, text='Show', command=show_entry_fields).grid(row=3, column=1, sticky=W, pady=4)
160
+   master = Tk()
161
+   master.title("Namen eingeben")
162
+   e1 = Entry(master)
163
+   e1.grid(row=0, column=1)
164
+   Button(master, text='Ok', command=show_entry_fields).grid(row=3, column=1, sticky=W, pady=4)
165
+   Button(master, text='Zurueck', command=master.destroy).grid(row=3, column=2, sticky=W, pady=4)
153 166
 
154 167
    mainloop()
155 168
 
@@ -172,10 +185,3 @@ if ball.hit_bottom == True:
172 185
 
173 186
     anzeige()
174 187
 
175
-#    tk=Tk()
176
-#    tk.title("Highscore-Liste")
177
-#    canvas = Canvas(tk, width=500, height=400, bd=2, bg="white")
178
-#    canvas.pack()
179
-
180
-#------------------------------------------------------------------------------------------------------------------
181
-