antiblock
https://arwen2.global/
  • Chatbox

    Did you check out our Discord? https://discord.gg/FFdvMjk9xA
    You don't have permission to chat.
    Load More
  • 0
VzOhMG

Criar botão e/ou dar função a ele

Question

Boas, olhei em vários cantos e até que aprendi a como criar um botão, porém após criar, devo dar uma função a ele... pois bem, é aí que estou travado, não consegui sacar onde fica os arquivos .py que eu devo editar para poder dar vida ao botão que criei...

 

Abaixo deixo uma imagem de um teste que estou fazendo, na qual tenho um botão (com a imagem  de uma seta para cima), e logo que eu clicasse nela, gostaria que subisse os icones do lado, do mesmo esquema que funciona o botão do atack normal e automatico, ao clicar nele, aparece 2 botões acima...

 

Consigo criar diversas funções, mas os botões não estao tendo essa 'vida'... como faço?

 

Imagem do botão

https://imgur.com/otUvFJS

 

função que eu gostaria de criar para que ele fizesse:

https://imgur.com/xJLd8NY

 

Agradeço muito a quem puder explicar, fucei em vários foruns porém nenhum com que fizesse um tut que passasse da etapa de criar (informar onde dá funções).

Share this post


Link to post
Share on other sites

1 answer to this question

  • 0

Aqui tens um exemplo, espero que te ajude.
54b1f673f10351f16269da49b38b489a.gif

#
# 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

 

Share this post


Link to post
Share on other sites
antiblock
https://arwen2.global/

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now