Skip to content

Commit bfe4d33

Browse files
committed
pygame,begin
1 parent f6b569d commit bfe4d33

92 files changed

Lines changed: 3058 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

python_GUI/gui2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import wx
2+
app = wx.PySimpleApp()
3+
frame = wx.Frame( None, -1,'')
4+
frame.SetToolTip( wx.ToolTip( 'this is a frame' )
5+
6+
#frame.SetCursor( wx.StockCursor( wx.CURSOR_MAGNIFIER))
7+
8+
#frame.SetPosition( wx.Point(0,0))
9+
#frame.SetSize(wx.Size(300,250))
10+
#frame.SetTitle('luyishisi.py')
11+
#frame.Show()
12+
13+
app.MainLoop()

python_GUI/gui3.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
# FileName: menu1.py
3+
import wx
4+
class MyMenu( wx.Frame ):
5+
def __init__(self,parent,ID,title):
6+
wx.Frame.__init__(self,parent,-1,title,wx.DefaultPosition,wx.Size(200, 150))
7+
menubar=wx.MenuBar()
8+
file=wx.Menu()
9+
edit=wx.Menu()
10+
help=wx.Menu()
11+
file.Append(101,'&Open','Open a new document')
12+
file.Append(102,'&Save','Save the document')
13+
file.AppendSeparator()
14+
quit=wx.MenuItem(file,105,'&Quit\tCtrl+Q','Quit the Application')
15+
quit.SetBitmap(wx.Image('stock_exit-16.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap())
16+
file.AppendItem(quit)
17+
menubar.Append(file,'&File')
18+
menubar.Append(edit,'&Edit')
19+
menubar.Append(help,'&Help')
20+
self.SetMenuBar( menubar )
21+
22+
class MyApp(wx.App):
23+
def OnInit(self):
24+
frame=MyMenu(None,-1,'menu1.py')
25+
frame.Show(True)
26+
return True
27+
28+
app=MyApp(0)
29+
app.MainLoop()

python_GUI/gui4.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import wx
2+
class MainWindow(wx.Frame):
3+
def __init__(self, parent, title):
4+
wx.Frame.__init__(self, parent, title=title, size=(300, 300))
5+
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
6+
7+
self.setupMenuBar()
8+
self.Show(True)
9+
10+
def setupMenuBar(self):
11+
self.CreateStatusBar()
12+
13+
menubar = wx.MenuBar()
14+
menufile = wx.Menu()
15+
16+
mnuabout = menufile.Append(wx.ID_ABOUT, '&About', 'about this shit')
17+
mnuexit = menufile.Append(wx.ID_EXIT, 'E&xit', 'end program')
18+
19+
menubar.Append(menufile, '&File')
20+
21+
self.Bind(wx.EVT_MENU, self.onAbout, mnuabout)
22+
self.Bind(wx.EVT_MENU, self.onExit, mnuexit)
23+
24+
self.SetMenuBar(menubar)
25+
26+
def onAbout(self, evt):
27+
dlg = wx.MessageDialog(self, 'This app is a simple text editor', 'About my app', wx.OK)
28+
dlg.ShowModal()
29+
dlg.Destroy()
30+
31+
def onExit(self, evt):
32+
self.Close(True)
33+
app = wx.App(False)
34+
frame = MainWindow(None, 'Small Editor')
35+
36+
app.MainLoop()

python_GUI/gui_alarm_clock.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
import time
3+
from PyQt4.QtCore import *
4+
from PyQt4.QtGui import *
5+
app = QApplication(sys.argv)
6+
try:
7+
message = "Alert!"
8+
if len(sys.argv) < 2:
9+
raise ValueError
10+
hours, mins = sys.argv[1].split(":")
11+
due = QTime(int(hours), int(mins))
12+
if not due.isValid():
13+
raise ValueError
14+
if len(sys.argv) > 2:
15+
message = " ".join(sys.argv[2:])
16+
except ValueError:
17+
message = "Usage: alert.pyw HH:MM [optional message]" # 24hr clock
18+
while QTime.currentTime() < due:
19+
time.sleep(20) # 20 seconds
20+
label = QLabel("<font color=red size=72><b>" + message + "</b></font>")
21+
label.setWindowFlags(Qt.SplashScreen)
22+
label.show()
23+
QTimer.singleShot(60000, app.quit) # 1 minute
24+
app.exec_()

python_game/1.jpg

508 KB
Loading

python_game/2.jpg

102 KB
Loading

python_game/game1.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#coding:utf-8
2+
background_image_filename = '1.jpg'
3+
mouse_image_filename = '2.jpg'
4+
#指定图像文件名称
5+
6+
import pygame
7+
#导入pygame库
8+
from pygame.locals import *
9+
#导入一些常用的函数和常量
10+
from sys import exit
11+
#向sys模块借一个exit函数用来退出程序
12+
13+
pygame.init()
14+
#初始化pygame,为使用硬件做准备
15+
16+
screen = pygame.display.set_mode((1024,960), 0, 32)
17+
#创建了一个窗口
18+
pygame.display.set_caption("Hello, World!")
19+
#设置窗口标题
20+
21+
background = pygame.image.load(background_image_filename).convert()
22+
mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()
23+
#加载并转换图像
24+
25+
while True:
26+
#游戏主循环
27+
28+
for event in pygame.event.get():
29+
if event.type == QUIT:
30+
#接收到退出事件后退出程序
31+
exit()
32+
33+
screen.blit(background, (0,0))
34+
#将背景图画上去
35+
36+
x, y = pygame.mouse.get_pos()
37+
#获得鼠标位置
38+
x-= mouse_cursor.get_width() / 2
39+
y-= mouse_cursor.get_height() / 2
40+
#计算光标的左上角位置
41+
screen.blit(mouse_cursor, (x, y))
42+
#把光标画上去
43+
44+
pygame.display.update()
45+
#刷新一下画面

python_pachong/0.jpg

39.4 KB
Loading

python_pachong/1.jpg

52 Bytes
Loading

python_pachong/10.jpg

8.56 KB
Loading

0 commit comments

Comments
 (0)