Python Forum
kivy: how to create a widget that represents a circled letter?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
kivy: how to create a widget that represents a circled letter?
#1
Hello,
[kivy]
how to create a widget that represents a circled letter?
I want to be able to move this widget to my root widget as I please. However, I can't associate the circle with the letter. The application I'm working on is a brick breaker structured like the pong in the tutorial.
Just to show some code, I attach a non functional one:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Ellipse
from kivy.uix.label import Label
from kivy.metrics import dp
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.properties import NumericProperty, ReferenceListProperty, ObjectProperty

Builder.load_string('''

<MyCircleWithLetter>:
    letter: "A"
    canvas:
        Color:
            rgba: 1, 1, 0, 1
        Ellipse:
            pos: self.center_x - dp(100), self.center_y - dp(100)
            size: dp(200), dp(200)
    Label:
        text: root.letter
        font_size: dp(100)
        pos: self.center_x - dp(50), self.center_y - dp(50)

<Widgetroot>:
    position: position
    MyCircleWithLetter:
        id: position
        pos: root.pos
        #self.center_x: Window.width//2
        #self.center_y: Window.height//2
''')

class MyCircleWithLetter(Widget):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        pass
    
class WidgetRoot(Widget):
    position: ObjectProperty()
    def __init__(self, **kwargs):
        self.pos = (Window.width, Window.height)
        super().__init__(**kwargs)
        
        
class MyPaintApp(App):
    def build(self):
        fl = WidgetRoot()
            
        return fl
if __name__ == "__main__":
    MyPaintApp().run()
Merci
I speak Python but I don't speak English (I just read it a little). If I express myself badly, please blame the translator^^.
Reply
#2
solved: Wink
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Ellipse
from kivy.uix.label import Label
from kivy.metrics import dp
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.properties import NumericProperty, ReferenceListProperty, ObjectProperty

Builder.load_string('''

<MyCircleWithLetter>:
    letter: "A"
    
    canvas:
        Color:
            rgba: 1, 1, 0, 1
        Ellipse:
            pos: self.center_x - dp(100), self.center_y - dp(100)
            size: dp(200), dp(200)
    Label:
        text: root.letter
        font_size: dp(100)
        pos: root.center_x - dp(50), root.center_y - dp(50)

<Widgetroot>:
    position: position
    MyCircleWithLetter:
        id: position
        pos: root.pos
       
''')

class MyCircleWithLetter(Widget):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        pass
    
class WidgetRoot(Widget):
    position: ObjectProperty()
    def __init__(self, **kwargs):
        self.pos = (Window.width//2, Window.height//2)
        super().__init__(**kwargs)
        
        
class MyPaintApp(App):
    def build(self):
        fl = WidgetRoot()
            
        return fl
if __name__ == "__main__":
    MyPaintApp().run()
I speak Python but I don't speak English (I just read it a little). If I express myself badly, please blame the translator^^.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PyGtk3, How to Create “title-changed” signal for Gtk.Window Widget? harun2525 2 6,105 May-01-2017, 07:59 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020