本文整理汇总了Python中Button.Button类的典型用法代码示例。如果您正苦于以下问题:Python Button类的具体用法?Python Button怎么用?Python Button使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Button类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
def draw(self):
if self.left + self.max_width <= self.parent.width - self.parent.bd_width - \
2 * self.parent.h_margin:
self.visible = True
else:
self.visible = False
Button.draw(self)
示例2: __init__
def __init__(self, x, y, text, parent, c=(255,0,0)):
Button.__init__(self, x, y, text, parent, c)
self.font = pygame.font.SysFont('Calibri', 12)
self.width -= 10
self.height = 20
self.surface = pygame.Surface((self.width, self.height))
self.render()
示例3: __init__
class WindowBar:
def __init__(self, parent, absx, absy, title=None):
self.x = 0
self.y = 0
self.absx = absx
self.absy = absy
self.parent = parent
self.width = self.parent.get_width()
self.height = 20
self.surface = pygame.Surface((self.width, self.height))
self.surface.fill((100,100,100))
self.title = title
if self.title != None:
self.button = Button(0, 0, self.title, self.surface, (100,100,100))
def is_clicked(self):
# doesn't actually check if clicked, just mouse over
mx, my = pygame.mouse.get_pos()
if mx > self.absx and mx < self.absx + self.width and my > self.absy and my < self.absy + self.height:
return True
def draw(self):
if self.title != None:
self.button.draw(self.surface)
self.parent.blit(self.surface, (self.x, self.y))
示例4: __init__
def __init__(self, game):
self.game = game
self.font = game.font
self.one_player_button = Button([300, 350], [200, 30], "1P VS AI", self.font)
self.one_player_button2 = Button([300, 400], [200, 30], "AI VS 1P", self.font)
self.two_player_button = Button([300, 450], [200, 30], "1P VS 2P", self.font)
示例5: searchSavedOthers
def searchSavedOthers(handler):
handler.title('Saved Searches')
requirePriv(handler, 'User')
print tabs.where('others')
undelay(handler)
print "<style type=\"text/css\">"
print ".other-search {padding-bottom: 4px; border-bottom: 1px dashed #000;}"
print ".other-search h2 {margin-bottom: 4px;}"
print ".other-search small {float: right; font-weight: normal; font-size: 12pt;}"
print ".other-search code {font-size: 14pt;}"
print "</style>"
searches = filter(lambda search: search.user != handler.session['user'] and search.public, SavedSearch.loadAll(orderby = 'name'))
if searches == []:
print "No shared searches available"
else:
for search in searches:
print "<div class=\"other-search\">"
print "<h2>%s<small><img class=\"bumpdown\" src=\"%s\"> %s</small></h2>" % (search.safe.name, search.user.getAvatar(16), search.user.username)
print "<code>%s</code><br><br>" % search.safe.query
following = handler.session['user'] in search.followers
print "<form method=\"post\" action=\"/search/saved/%d/%s\">" % (search.id, 'unfollow' if following else 'follow')
print Button('Run', url = "/search/saved/%d/run" % search.id)
btn = Button('Unfollow' if following else 'Follow', type = 'submit')
if following:
btn.negative()
else:
btn.positive()
print btn
print "</form>"
print "</div>"
示例6: start
def start(self):
global actual_state
clock = pygame.time.Clock()
running_menu = True
while running_menu:
#fica checando se o estado == game pra mudar
#se nao continua no menu (e so muda quando clicar
clock.tick(120)
buttonStart = Button([width/2,height/2])
for event in pygame.event.get():
if event.type==QUIT:
running_menu = False
elif event.type == MOUSEBUTTONDOWN:
if buttonStart.pressed(pygame.mouse.get_pos()):
actual_state = gamestate["game"]
running_menu = False
screen.fill(white)
screen.blit(buttonStart.btn, buttonStart.btnrect)
pygame.display.flip()
示例7: __init__
def __init__(self, parent=None, rect=sf.Rectangle(), backgroundColor=sf.Color.BLACK,\
title=str(), backgroundImage=Image(), drawTitleButton = True,\
buttonTitleImage=None, \
characterSizeTitle=12):
sf.RenderTexture.__init__(self, rect.size.x, rect.size.y)
Render.__init__(self, parent, rect, backgroundColor, title, backgroundImage)
self._buttonMoveFrame = None
if type(title) == str:
self._title = title
self._buttonMoveFrame = Button(self, Label(None, self.title, font = sf.Font.from_file("DejaVuSans.ttf")), \
buttonTitleImage, sf.Rectangle(sf.Vector2(0,0),\
sf.Vector2(self.size.x, characterSizeTitle)))
else:
self._title = title.text.string
self._buttonMoveFrame = Button(self, title, buttonTitleImage, \
sf.Rectangle(sf.Vector2(), sf.Vector2(self.size.x, \
title.size.y)))
self._buttonMoveFrame.isStaticToView = True
self.resetView()
self._frameSprite = sf.Sprite(self.texture)
if not drawTitleButton:
self._buttonMoveFrame.isDrawing = False
self._isMoving = False
self._mousePosMoving = sf.Vector2(0, 0)
self.rect = self.rect
示例8: __init__
def __init__(self, Parent, Message, **properties):
SIOInstance = Parent.Screen()
sMCOL = SIOInstance.MAXCOL
sMROW = SIOInstance.MAXROW
MsgLen = len(Message)
DialogWidth = MsgLen + 4
DialogHeight = 6
if DialogWidth < 12:
DialogWidth = 18
r1 = (sMROW - DialogHeight) / 2
r2 = r1 + DialogHeight
c1 = (sMCOL - DialogWidth) / 2
c2 = c1 + DialogWidth
apply(Dialog.__init__, (self, Parent, r1, c1, r2, c2), properties)
tCmdYes = Button(self, "YesBtn", 5, (DialogWidth - 7) / 4, 7, "Yes")
tCmdYes.EXITFORM = 1
self.AddDialogControl(tCmdYes)
tCmdNo = Button(self, "NoBtn", 5, 2 + (2 * ((DialogWidth - 7)) / 4), 7, "No")
tCmdNo.EXITFORM = 1
self.AddDialogControl(tCmdNo)
self.AddDialogControl(Label(self, "TheMsg", 1, 2, Message))
示例9: __init__
def __init__(self, Parent, Message, **properties):
SIOInstance = Parent.Screen()
sMCOL = SIOInstance.MAXCOL
sMROW = SIOInstance.MAXROW
MsgLen = len(Message)
DialogWidth = MsgLen + 4
DialogHeight = 6
# adjust dialog, if need be, to hold OK btn comfortably
if DialogWidth < 6:
DialogWidth = 10
r1 = (sMROW - DialogHeight) / 2
r2 = r1 + DialogHeight
c1 = (sMCOL - DialogWidth) / 2
c2 = c1 + DialogWidth
apply(Dialog.__init__, (self, Parent, r1, c1, r2, c2), properties)
tCmd = Button(self, "TheBtn", 5, (DialogWidth - 6) / 2, 6, "OK")
tCmd.EXITFORM = 1
self.AddDialogControl(tCmd)
self.AddDialogControl(Label(self, "TheMsg", 1, 2, Message))
示例10: __init__
def __init__(self, Parent, Prompt, DefaultText="", **properties):
SIOInstance = Parent.Screen()
sMCOL = SIOInstance.MAXCOL
sMROW = SIOInstance.MAXROW
if len(Prompt) < 40:
DialogWidth = 40
else:
DialogWidth = len(Prompt) + 4
DialogHeight = 6
r1 = (sMROW - DialogHeight) / 2
r2 = r1 + DialogHeight
c1 = (sMCOL - DialogWidth) / 2
c2 = c1 + DialogWidth
apply(Dialog.__init__, (self, Parent, r1, c1, r2, c2), properties)
tCmdOK = Button(self, "OKBtn", 5, (DialogWidth - 10) / 4, 10, "OK")
tCmdOK.EXITFORM = 1
self.AddDialogControl(tCmdOK)
tCmdCancel = Button(self, "CnclBtn", 5, 2 + (2 * ((DialogWidth - 10)) / 4), 10, "Cancel")
tCmdCancel.EXITFORM = 1
self.AddDialogControl(tCmdCancel)
self.AddDialogControl(Label(self, "lbl", 1, 2, Prompt))
self.tTextBox = TextBox(self, "txtBox", 2, 2, DialogWidth - 4, DefaultText)
self.tTextBox.DEPTH = len(DefaultText)
self.AddDialogControl(self.tTextBox)
self.STARTPOINT = 3
示例11: __init__
def __init__ (self, text):
Button.__init__ (self, text)
# Internal click handler
self.__click = False
self._active = False
# The ToggleButton emits a 'toggled' event.
self._signals[SIG_TOGGLED] = []
示例12: __init__
def __init__ (self, caption, _props={}):
# Properties
props = _props.copy()
if 'class' in props:
props['class'] += ' druid-button'
else:
props['class'] = 'druid-button'
# Parent's constructor
Button.__init__ (self, caption, props)
示例13: __init__
def __init__(self, parent, **kwargs):
Button.__init__(self, parent)
# data
self.direction = ALIGN_N
# del
del self.text
del self.icons
# flags
self.processKWArguments(kwargs)
parent.registerWidget(self)
示例14: Welcome
class Welcome():
def __init__(self, game):
self.game = game
self.font = game.font
self.one_player_button = Button([300, 350], [200, 30], "1P VS AI", self.font)
self.one_player_button2 = Button([300, 400], [200, 30], "AI VS 1P", self.font)
self.two_player_button = Button([300, 450], [200, 30], "1P VS 2P", self.font)
def draw(self):
game = self.game
screen = game.screen
self.one_player_button.draw(screen)
self.one_player_button2.draw(screen)
self.two_player_button.draw(screen)
def handle_key_event(self, e):
game = self.game
pos = e.pos
if self.one_player_button.check(pos):
game.window = 1
game.with_AI = True
game.AI_first = True
elif self.one_player_button2.check(pos):
game.window = 1
game.with_AI = True
game.AI_first = False
elif self.two_player_button.check(pos):
game.window = 1
game.with_AI = False
示例15: __init__
def __init__(self, pX, pY, pText, pColor=BLACK, pFontSize=36, pMethod=None, pName=None, pParams=None):
'''
Constructor
'''
if pName == None:
name = pText
else:
name = pName
Button.__init__(self, pX, pY, pName=name, pMethod=pMethod, pParams=pParams)
font = pygame.font.Font(None, pFontSize)
self.text = font.render(pText, 1, (pColor))