http://people.ubuntu.com/~kelemeng/.ufp3/your-first-python-program.html
Fallabda játék ablaka
Fallabda játék forrása
from Tkinter import *
# Fallabda
class App
(Frame):
def __init__(self, master=None):
Frame.__init__(self,master)
Pack.config(self)
self.s=0 # Pontok
self.x=280 # Labda
self.y=5
self.vx=4 #Labda sebessege
self.vy=4 #Labda sebessege
self.px=250 #Jatekos
self.py=0
self.w()
self.after(10, self.moveBall)
def w(self):
self.l=Canvas(self,bg='yellow', width="300",heigh="220")
self.l.pack()
self.m=Label(self,relief='groove', text="",anchor="w")
self.m.pack(side='top',fill="x")
self.player= self.l.create_rectangle(self.px, self.py, self.px + 7, self.py + 30,
{"fill" : 'black',"tags":"p1"})
self.ball = self.l.create_rectangle(280, 5, 290, 15,
{"fill":'red',"tags":"ball"})
self.bind_all("<Up>", self.fel)
self.bind_all("<Down>", self.le)
self.bind_all("<B1-Motion>",self.Move)
self.m.configure(text="Score : "+`self.s`)
def Move(self, event):
if CURRENT <> "ball":
self.l.move(CURRENT, 0, event.y-self.py)
self.py=event.y
def fel(self, event):
self.l.move("p1", 0,-10)
self.py=self.py-10
def le(self, event):
self.l.move("p1",0,10)
self.py=self.py+10
def moveBall(self,*args):
if (self.x+10 == self.px) and (self.vx < 0) and (self.py - 11 < self.y) and (self.py + 36 > self.y):
self.s=self.s+1
self.m.configure(text ="Score : "+`self.s`)
self.vx=self.vx * -1
if (self.x < 4 )or(self.x>288) :
self.vx=-1.0 * self.vx
if (self.y > 211) or (self.y < 4):
self.vy=-1.0 * self.vy
self.x=self.x - self.vx
self.y=self.y + self.vy
self.l.move("ball",-self.vx,self.vy )
self.after(10, self.moveBall)
if __name__=='__main__':
# root = Tk()
app = PApp()
app.mainloop()
Online futtató környezet
https://www.programiz.com/python-programming/online-compiler/
Könyv
http://mek.oszk.hu/08400/08436/08436.pdf
Ablak nyitása
import tkinter as tk
import tkinter.ttk as ttk
class App:
def __init__(self, master=None):
self.master = master
# Window 1 widgets
self.frame1 = ttk.Frame(master, width=300, height=150, relief='groove')
self.frame1.pack_propagate(False)
self.label1 = ttk.Label(self.frame1, text='This is window 1')
self.button1 = ttk.Button(self.frame1, text='Go to window 2', command=self.window2)
self.button2 = ttk.Button(self.frame1, text='Go to window 3', command=self.window3)
# Window 2 widgets
self.frame2 = ttk.Frame(master, width=300, height=150, relief='groove')
self.frame2.pack_propagate(False)
self.label2 = ttk.Label(self.frame2, text='This is window 2')
self.button3 = ttk.Button(self.frame2, text='Go to window 1', command=self.window1)
self.button4 = ttk.Button(self.frame2, text='Go to window 3', command=self.window3)
# Window 3 widgets
self.frame3 = ttk.Frame(master, width=300, height=150, relief='groove')
self.frame3.pack_propagate(False)
self.label3 = ttk.Label(self.frame3, text='This is window 3')
self.button5 = ttk.Button(self.frame3, text='Go to window 1', command=self.window1)
self.button6 = ttk.Button(self.frame3, text='Go to window 2', command=self.window2)
self.window1()
def window1(self):
self.forget_widgets()
self.frame1.pack(side='top', pady=(25, 0))
self.label1.pack(side='top', pady=(25, 25))
self.button1.pack(side='top', pady=(0, 5))
self.button2.pack(side='top')
def window2(self):
self.forget_widgets()
self.frame2.pack(side='top', pady=(25, 0))
self.label2.pack(side='top', pady=(25, 25))
self.button3.pack(side='top', pady=(0, 5))
self.button4.pack(side='top')
def window3(self):
self.forget_widgets()
self.frame3.pack(side='top', pady=(25, 0))
self.label3.pack(side='top', pady=(25, 25))
self.button5.pack(side='top', pady=(0, 5))
self.button6.pack(side='top')
def forget_widgets(self):
for widget in self.master.winfo_children():
widget.pack_forget()
if __name__ == '__main__':
root = tk.Tk()
root.geometry('350x200')
App(master=root)
root.mainloop()
Példa ablakban
class App: Width = 800 *window dimension
Height = 600
player = 0 *to track either human or computer
Frog = 0 *food
def init (self):
self._running = True
self.surface None
self._image_surf = None
self._Frog_surf = None
self.game = Game()
self.player = Player(5) *instance of Player with length 5 (5 blocks)
self.Frog = Frog(8, 5) *instance of Frog with x and y position self.computer = Computer(5) *instance of Computer player
with length 5
https://blog.jetbrains.com/pycharm/page/2/
Fallabda játék ablaka
Fallabda játék forrása
from Tkinter import *
# Fallabda
class App
(Frame):
def __init__(self, master=None):
Frame.__init__(self,master)
Pack.config(self)
self.s=0 # Pontok
self.x=280 # Labda
self.y=5
self.vx=4 #Labda sebessege
self.vy=4 #Labda sebessege
self.px=250 #Jatekos
self.py=0
self.w()
self.after(10, self.moveBall)
def w(self):
self.l=Canvas(self,bg='yellow', width="300",heigh="220")
self.l.pack()
self.m=Label(self,relief='groove', text="",anchor="w")
self.m.pack(side='top',fill="x")
self.player= self.l.create_rectangle(self.px, self.py, self.px + 7, self.py + 30,
{"fill" : 'black',"tags":"p1"})
self.ball = self.l.create_rectangle(280, 5, 290, 15,
{"fill":'red',"tags":"ball"})
self.bind_all("<Up>", self.fel)
self.bind_all("<Down>", self.le)
self.bind_all("<B1-Motion>",self.Move)
self.m.configure(text="Score : "+`self.s`)
def Move(self, event):
if CURRENT <> "ball":
self.l.move(CURRENT, 0, event.y-self.py)
self.py=event.y
def fel(self, event):
self.l.move("p1", 0,-10)
self.py=self.py-10
def le(self, event):
self.l.move("p1",0,10)
self.py=self.py+10
def moveBall(self,*args):
if (self.x+10 == self.px) and (self.vx < 0) and (self.py - 11 < self.y) and (self.py + 36 > self.y):
self.s=self.s+1
self.m.configure(text ="Score : "+`self.s`)
self.vx=self.vx * -1
if (self.x < 4 )or(self.x>288) :
self.vx=-1.0 * self.vx
if (self.y > 211) or (self.y < 4):
self.vy=-1.0 * self.vy
self.x=self.x - self.vx
self.y=self.y + self.vy
self.l.move("ball",-self.vx,self.vy )
self.after(10, self.moveBall)
if __name__=='__main__':
# root = Tk()
app = PApp()
app.mainloop()
Online futtató környezet
https://www.programiz.com/python-programming/online-compiler/
Könyv
http://mek.oszk.hu/08400/08436/08436.pdf
Ablak nyitása
import tkinter as tk
import tkinter.ttk as ttk
class App:
def __init__(self, master=None):
self.master = master
# Window 1 widgets
self.frame1 = ttk.Frame(master, width=300, height=150, relief='groove')
self.frame1.pack_propagate(False)
self.label1 = ttk.Label(self.frame1, text='This is window 1')
self.button1 = ttk.Button(self.frame1, text='Go to window 2', command=self.window2)
self.button2 = ttk.Button(self.frame1, text='Go to window 3', command=self.window3)
# Window 2 widgets
self.frame2 = ttk.Frame(master, width=300, height=150, relief='groove')
self.frame2.pack_propagate(False)
self.label2 = ttk.Label(self.frame2, text='This is window 2')
self.button3 = ttk.Button(self.frame2, text='Go to window 1', command=self.window1)
self.button4 = ttk.Button(self.frame2, text='Go to window 3', command=self.window3)
# Window 3 widgets
self.frame3 = ttk.Frame(master, width=300, height=150, relief='groove')
self.frame3.pack_propagate(False)
self.label3 = ttk.Label(self.frame3, text='This is window 3')
self.button5 = ttk.Button(self.frame3, text='Go to window 1', command=self.window1)
self.button6 = ttk.Button(self.frame3, text='Go to window 2', command=self.window2)
self.window1()
def window1(self):
self.forget_widgets()
self.frame1.pack(side='top', pady=(25, 0))
self.label1.pack(side='top', pady=(25, 25))
self.button1.pack(side='top', pady=(0, 5))
self.button2.pack(side='top')
def window2(self):
self.forget_widgets()
self.frame2.pack(side='top', pady=(25, 0))
self.label2.pack(side='top', pady=(25, 25))
self.button3.pack(side='top', pady=(0, 5))
self.button4.pack(side='top')
def window3(self):
self.forget_widgets()
self.frame3.pack(side='top', pady=(25, 0))
self.label3.pack(side='top', pady=(25, 25))
self.button5.pack(side='top', pady=(0, 5))
self.button6.pack(side='top')
def forget_widgets(self):
for widget in self.master.winfo_children():
widget.pack_forget()
if __name__ == '__main__':
root = tk.Tk()
root.geometry('350x200')
App(master=root)
root.mainloop()
Példa ablakban
class App: Width = 800 *window dimension
Height = 600
player = 0 *to track either human or computer
Frog = 0 *food
def init (self):
self._running = True
self.surface None
self._image_surf = None
self._Frog_surf = None
self.game = Game()
self.player = Player(5) *instance of Player with length 5 (5 blocks)
self.Frog = Frog(8, 5) *instance of Frog with x and y position self.computer = Computer(5) *instance of Computer player
with length 5
https://blog.jetbrains.com/pycharm/page/2/
Nincsenek megjegyzések:
Megjegyzés küldése