Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit94d3800

Browse files
committed
add long description to cse api tutorial
1 parent980cc85 commit94d3800

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

‎general/using-custom-search-engine-api/search_engine.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
search_items=data.get("items")
3131
# iterate over 10 results found
3232
fori,search_iteminenumerate(search_items,start=1):
33+
try:
34+
long_description=search_item["pagemap"]["metatags"][0]["og:description"]
35+
exceptKeyError:
36+
long_description="N/A"
3337
# get the page title
3438
title=search_item.get("title")
3539
# page snippet
@@ -42,4 +46,5 @@
4246
print("="*10,f"Result #{i+start-1}","="*10)
4347
print("Title:",title)
4448
print("Description:",snippet)
49+
print("Long description:",long_description)
4550
print("URL:",link,"\n")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#[How to Make a Button using PyGame in Python](https://www.thepythoncode.com/article/make-a-button-using-pygame-in-python)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Imports
2+
importsys
3+
importpygame
4+
5+
# Configuration
6+
pygame.init()
7+
fps=60
8+
fpsClock=pygame.time.Clock()
9+
width,height=640,480
10+
screen=pygame.display.set_mode((width,height))
11+
12+
font=pygame.font.SysFont('Arial',40)
13+
14+
objects= []
15+
16+
classButton():
17+
def__init__(self,x,y,width,height,buttonText='Button',onclickFunction=None,onePress=False):
18+
self.x=x
19+
self.y=y
20+
self.width=width
21+
self.height=height
22+
self.onclickFunction=onclickFunction
23+
self.onePress=onePress
24+
25+
self.fillColors= {
26+
'normal':'#ffffff',
27+
'hover':'#666666',
28+
'pressed':'#333333',
29+
}
30+
31+
self.buttonSurface=pygame.Surface((self.width,self.height))
32+
self.buttonRect=pygame.Rect(self.x,self.y,self.width,self.height)
33+
34+
self.buttonSurf=font.render(buttonText,True, (20,20,20))
35+
36+
self.alreadyPressed=False
37+
38+
objects.append(self)
39+
40+
defprocess(self):
41+
42+
mousePos=pygame.mouse.get_pos()
43+
44+
self.buttonSurface.fill(self.fillColors['normal'])
45+
ifself.buttonRect.collidepoint(mousePos):
46+
self.buttonSurface.fill(self.fillColors['hover'])
47+
48+
ifpygame.mouse.get_pressed(num_buttons=3)[0]:
49+
self.buttonSurface.fill(self.fillColors['pressed'])
50+
51+
ifself.onePress:
52+
self.onclickFunction()
53+
54+
elifnotself.alreadyPressed:
55+
self.onclickFunction()
56+
self.alreadyPressed=True
57+
58+
else:
59+
self.alreadyPressed=False
60+
61+
self.buttonSurface.blit(self.buttonSurf, [
62+
self.buttonRect.width/2-self.buttonSurf.get_rect().width/2,
63+
self.buttonRect.height/2-self.buttonSurf.get_rect().height/2
64+
])
65+
screen.blit(self.buttonSurface,self.buttonRect)
66+
67+
defmyFunction():
68+
print('Button Pressed')
69+
70+
customButton=Button(30,30,400,100,'Button One (onePress)',myFunction)
71+
customButton=Button(30,140,400,100,'Button Two (multiPress)',myFunction,True)
72+
73+
# Game loop.
74+
whileTrue:
75+
screen.fill((20,20,20))
76+
foreventinpygame.event.get():
77+
ifevent.type==pygame.QUIT:
78+
pygame.quit()
79+
sys.exit()
80+
81+
forobjectinobjects:
82+
object.process()
83+
84+
pygame.display.flip()
85+
fpsClock.tick(fps)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pygame

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp