from kivy.app import Appfrom kivy.core.window import Windowfrom kivy.graphics import Color, Rectanglefrom kivy.uix.widget import Widgetfrom kivy.uix.label import Labelfrom kivy.uix.floatlayout import FloatLayoutfrom kivy.uix.relativelayout import RelativeLayout
class Quadlabel(RelativeLayout):
def __init__(self, **kwargs): super(Quadlabel, self).__init__(**kwargs) print("self.size, size_hint, pos, pos_hint are:", self.size, self.size_hint, self.pos, self.pos_hint) with self.canvas.before: Color(0.2, 0.2, 0.2, 1) self.rect = Rectangle(size=self.size) self.TL = Label(text="TL", bold=True, color=(1,0,0,1), pos=(0.25*self.width, 0.7*self.height)) self.add_widget(self.TL) self.TR = Label(text="TR", bold=True, color=(1,1,0,1), pos=(0.75*self.width, 0.7*self.height)) self.add_widget(self.TR) self.BR = Label(text="BR", bold=True, color=(0,1,0,1), pos=(0.75*self.width, 0.3*self.height)) self.add_widget(self.BR) self.BL = Label(text="BL", bold=True, color=(0,0,1,1), pos=(0.25*self.width, 0.3*self.height)) self.add_widget(self.BL)
class MainApp(App):
def build(self): self.root = FloatLayout() self.root.add_widget(Quadlabel(size=(96,96), pos=(100, 0))) self.root.add_widget(Quadlabel(size=(96,96), pos=(0, 100)))
if __name__ == '__main__':
Window.size = (500, 400) MainApp().run()
self.size, size_hint, pos, pos_hint are: [96, 96] [1, 1] [100, 0] {}self.size, size_hint, pos, pos_hint are: [96, 96] [1, 1] [0, 100] {}
[INFO ] [Logger ] Record log in C:\Users\SES\.kivy\logs\kivy_20-05-23_49.txt
[INFO ] [deps ] Successfully imported "kivy_deps.gstreamer" 0.2.0
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.2.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.2.0
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.2.0
[INFO ] [Kivy ] v1.11.1
[INFO ] [Kivy ] Installed at "C:\Prog\Python37\lib\site-packages\kivy\__init__.py"
[INFO ] [Python ] v3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at "C:\Prog\Python37\python.exe"
[INFO ] [Factory ] 184 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used <glew>
[INFO ] [GL ] OpenGL version <b'4.6.0 NVIDIA 445.87'>
[INFO ] [GL ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO ] [GL ] OpenGL renderer <b'GeForce RTX 2070 SUPER/PCIe/SSE2'>
[INFO ] [GL ] OpenGL parsed version: 4, 6
[INFO ] [GL ] Shading version <b'4.60 NVIDIA'>
[INFO ] [GL ] Texture max size <32768>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Text ] Provider: sdl2
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
You are positioning the labels based on the height and width of the labels. I’d recommend using pos_hint, to position the labels.
I've been pounding my head against the wall for several hours trying to make sense of this. I can't find anything that would explain the offsets of the labels compared to the rectangles. I know there has to be SOMETHING that's offsetting the positions of the labels, and I read this part pretty carefully, but it doesn't apply - if I change the "BR" pos=() expression to "pos=(0,0)", I get this:
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4b507ca0-e53e-44c7-9a13-a4fc316f5da0%40googlegroups.com.
self.TL = Label(text="TL", bold=True, color=(1,0,0,1), pos_hint={'center_x':0.25, 'center_y':0.7})
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
If you have not used the inspector, I highly recommend it.
On the command line type: python myapp.py -m inspector
Then press cntrl-e and click on the widgets to see what they are. Experiment with the tool – it is outstanding. All the buttons show more info. There are somethings you can edit right in the tool.
We did it at the same time…
from kivy.app import App
from kivy.core.window import Window
from kivy.graphics import Color, Rectangle
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.relativelayout import RelativeLayout
class Quadlabel(RelativeLayout):
def __init__(self, **kwargs):
super(Quadlabel, self).__init__(**kwargs)
print("self.size, size_hint, pos, pos_hint are:", self.size, self.size_hint, self.pos, self.pos_hint)
with self.canvas.before:
Color(0.2, 0.2, 0.2, 1)
self.rect = Rectangle(size=self
.size)
self.TL = Label(text="TL", bold=True, color=(1,0,0,1), pos=(0.25*self.width, 0.7*self.height),
size_hint=(None,None), size=(10,10))
self.add_widget(self.TL)
self.TR = Label(text="TR", bold=True, color=(1,1,0,1), pos=(0.75*self.width, 0.7*self.height),
size_hint=(None,None), size=(10,10))
self.add_widget(self.TR)
self.BR = Label(text="BR", bold=True, color=(0,1,0,1), pos=(0.75*self.width, 0.3*self.height),
size_hint=(None,None), size=(10,10))
self.add_widget(self.BR)
self.BL = Label(text="BL", bold=True, color=(0,0,1,1), pos=(0.25*self.width, 0.3*self.height),
size_hint=(None,None), size=(10,10))
self.add_widget(self.BL)
class Main99App(App):
def build(self):
self.root = FloatLayout()
self.root.add_widget(Quadlabel(size=(96,96), pos=(100, 0)))
self.root.add_widget(Quadlabel(size=(96,96), pos=(0, 100)))
return self.root
if __name__ == '__main__':
Window.size = (500, 400
)
Main99App().run()
From: Steven Summers
Sent: Saturday, May 23, 2020 9:04 PM
To: Kivy users support
I've been pounding my head against the wall for several hours trying to make sense of this. I can't find anything that would explain the offsets of the labels compared to the rectangles. I know there has to be SOMETHING that's offsetting the positions of the labels, and I read this part pretty carefully, but it doesn't apply - if I change the "BR" pos=() expression to "pos=(0,0)", I get this:
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/2b3a9a13-9c46-43ea-9e42-877355de22ea%40googlegroups.com.