VzOhMG reacted to
Owsap in Criar botão e/ou dar função a ele
Aqui tens um exemplo, espero que te ajude.
#
# Title: Expanded Window
# Date: 2021.03.16
# Author: Owsap
import app
import ui
BUTTON_COUNT = 4
class TestWindow(ui.BoardWithTitleBar):
def __init__(self):
ui.BoardWithTitleBar.__init__(self)
self.isLoaded = False
self.btnExpanded = False
self.btnList = []
if not self.isLoaded:
self.__LoadBoard()
def __del__(self):
ui.BoardWithTitleBar.__del__(self)
def __LoadBoard(self):
self.SetSize(95, 210)
self.SetCenterPosition()
self.AddFlag('movable')
self.SetTitleName("Test")
self.SetCloseEvent(self.Close)
textLineGuide = ui.TextLine()
textLineGuide.SetParent(self)
textLineGuide.SetPosition(45, 185)
textLineGuide.SetText(".")
textLineGuide.Show()
self.textLineGuide = textLineGuide
btnExpand = ui.Button()
btnExpand.SetParent(self)
btnExpand.SetUpVisual("d:/ymir work/ui/public/small_button_01.sub")
btnExpand.SetOverVisual("d:/ymir work/ui/public/small_button_02.sub")
btnExpand.SetDownVisual("d:/ymir work/ui/public/small_button_03.sub")
btnExpand.SetText("+")
btnExpand.SetPosition(25, 160)
btnExpand.SetEvent(self.__OnClickExpand)
btnExpand.Show()
self.btnExpand = btnExpand
(xLocal, yLocal) = self.btnExpand.GetLocalPosition()
btnGroup = ui.Window()
btnGroup.SetParent(self)
btnGroup.SetPosition(xLocal, yLocal - 0 - (30 * BUTTON_COUNT))
btnGroup.SetSize(40, 30 * BUTTON_COUNT)
btnGroup.Hide()
self.btnGroup = btnGroup
for btnIdx in xrange(BUTTON_COUNT):
btn = ui.Button()
btn.SetParent(self.btnGroup)
btn.SetUpVisual("d:/ymir work/ui/public/small_button_01.sub")
btn.SetOverVisual("d:/ymir work/ui/public/small_button_02.sub")
btn.SetDownVisual("d:/ymir work/ui/public/small_button_03.sub")
btn.SetText("{}".format(btnIdx))
btn.SetPosition(0, (30 * btnIdx))
btn.SetEvent(lambda arg = btnIdx: self.__OnClickExpandedBtn(arg))
btn.Show()
self.btnList.append(btn)
def __OnClickExpand(self):
if not self.btnExpanded:
self.btnExpanded = True
self.btnGroup.Show()
if self.btnExpand:
self.btnExpand.SetText("-")
else:
self.btnExpanded = False
self.btnGroup.Hide()
if self.btnExpand:
self.btnExpand.SetText("+")
if self.textLineGuide:
self.textLineGuide.SetText(".")
def __OnClickExpandedBtn(self, arg):
if self.textLineGuide:
self.textLineGuide.SetText("{}".format(arg))
def Open(self):
self.Show()
def Close(self):
self.Hide()
def OnPressEscapeKey(self):
self.Close()
return True
def OnPressExitKey(self):
self.Close()
return True