#Getting the button inside a View class
1 messages · Page 1 of 1 (latest)
can we get more context? we generally execute code inside the button's callback method where you can modify the button's .view
Sure
I was trying to create a small pixel canvas editor as a proof of concept
It uses PIL to display the canvas
Planning to use buttons to let user to navigate the control
As users may need to move their cursor to (234, 0) we need a faster "go right" button
So I want to create a button that modifies the control key to go 8 pixels at once, not 1
My Editor view currently Looks like this: https://paste.nextcord.dev/?id=1743230283044985&language=python
The command is nothing more than a interaction.send(view=Editor(canvas, (0, 0), (0, 0), interaction))
Sorry if theres too many info, my codebase is a mess
The ">>/>" button should be able to control that
The view class has a children variable that contains all buttons/dropdowns.*
You can access it directly or create a dict with keys that are more readable. Keep in mind that after editing the buttons you need to include , view = self in the edit call.
-# * - Provided that you have already initialised the class.
Thank you! I am able to access them in self.children but I have no idea how to turn the Item[Unknown] to normal Button...
How can I turn the buttons in self.children into proper ui.Button classes?
wdym Item unknown?
.children returns list[Item] and does not offer the autocomplete to the subclasses right?
you can just pick an item
btn: nextcord.ui.Button = children[0]
and typehint it to be a button
it will still show a warning that you might not get a button if __getitem__ing that list but will still work and autocomplete the methods and attrs
It does show an error
I use a cast there (standard type checking)
what error