Scatter Widget problem

94 views
Skip to first unread message

Dan Moormann

unread,
Aug 15, 2023, 11:35:49 PM8/15/23
to Kivy users support
I've been using the Scatter widget tutorial as a launch pad to learn python/kivy/kv.  I've added a lot of stuff to the original program and have made a lot of changes.  Most noticeably I've added buttons to learn more about size and position.  This includes a display and drawing of the widgets (using turtle).  I've recently reordered the widgets and placed most of them in a FloatLayout in order to get absolute positioning.  This seems to work.

Unfortunately, when I click on the Hello!/label and/or move and/or rotate.  None of my buttons respond.  enclosed is my code.  If anyone can help or would like to use any of the code please do.  All the buttons respond properly if I don't touch the Hello/label.

By the way - a huge thankyou to Eliot for all of his help!

#:kivy 1.0.9

<ScatterTextWidget>:
orientation: 'vertical'
id: 'Main'
name: 'Main'

FloatLayout:
id: floa
name: 'floa'
on_size: app._reposition()
color: 0,255,255,1 #aqua

Label:
id: titl
name: 'titl'
text: 'Enter Text - Version: '+kivy.platform
size_hint_y: None
height: dp(50)
font_size: sp(20)
pos: 0,550
background_color: 0,0,128,1 #'navy'

TextInput:
id: txti
name: 'txti'
size_hint_y: None
height: dp(50)
font_size: '25sp'
pos: 0,500
focus: True
on_text: helo.text = self.text #change helo to match txti entered
#background_color:
#color: 255,0,0,1 #red

Label: #widget display text
id: disp
name: 'disp'
text: 'disp' #root.xltxt
font_name: root.xfontname
font_size: 14
size_hint_y: None
size: 800,400
pos: 0,0
background_color: 255,255,0,1 #yellow

Scatter:
id: scat
name: 'scat'
gid: scat
on_touch_up: root.set_focus()
#pos: 200,200
background_color: 0,255,0,1 #'lime'

Label: #hello
id: helo
name: 'helo'
text: "Hello!"
#font_size: '90sp'
font_size: 50
#pos_hint: {'center_x':.5, 'center_y':.6}
pos: 350,345
color: 'teal'
background_color: 0,128,128,1 #'teal'

Button:
id:lsiz
name: 'lsiz'
text: " Press\n to\ndisplay"
on_press: root.Listsizes(0)
on_release: root.set_focus()
size_hint_y: None
size_hint: root.xbutsiz
pos_hint: {'x':root.xbutxpos, 'top':.80}
background_color: 0,255,0,1 #green
color: 'black'

Button: #list sizes to file
id: lfil
name: 'lfil'
text: "Press\n to\n file"
on_press: root.Listsizes(1)
on_release: root.set_focus()
size_hint_y: None
size_hint: root.xbutsiz
pos_hint: {'x':root.xbutxpos*2, 'top':.80}
background_color: 0,0,255,1 #blue
color: 'black'

Button: #clear
id: clea
name: 'clea'
text: 'Clear'
on_press: disp .text=''
on_release: root.clear_it()
size_hint_y: None
size_hint: root.xbutsiz
pos_hint: {'x':root.xbutxpos*3, 'top':.80}
background_color: 255,0,0,1 #red
color: 'black'

Button: #mode
id: mode
name: 'mode'
text: 'Mode\n '+root.xmode
on_press: root.set_mode()
on_release: root.set_focus()
size_hint_y: None
size_hint: root.xbutsiz
pos_hint: {'x':root.xbutxpos*4, 'top':.80}
background_color: 255,255,0,1 #yellow
color: 'black'

Button: #draw
id: draw
name: 'draw'
text: "Draw"
on_press: root.drawit()
on_release: root.set_focus()
size_hint_y: None
size_hint: root.xbutsiz
pos_hint: {'x':root.xbutxpos*5, 'top':.80}
background_color: 128,0,128,1 #'purple'
color: 'black'

Button: #xtest
id: test
name: 'test'
on_press: root.xtest()
text: 'xtest'
size_hint_y: None
size_hint: root.xbutsiz
pos_hint: {'x':root.xbutxpos*6, 'top':.80}
background_color: 128,128,128,1 #'maroon'
color: 'black'

import os
from kivy.app import App
from kivy.properties import ColorProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.utils import platform
from kivy.core.window import Window
from webcolors import rgb_to_name
from PIL import ImageGrab
import win32gui
hwnd = win32gui.GetForegroundWindow()
#win32gui.MoveWindow(hwnd, 1380,50,816,639,True) #move console output to monitor 0

xmode= 'W' # Win/Emulate/Android
#print(Window.size)
class ScatterTextWidget(BoxLayout):
background_color = ColorProperty() # The ListProperty will also work.
xltxt = ""
if platform == 'android':
xmode="A"
from android.storage import primary_external_storage_path
dir = primary_external_storage_path()
xfontname=os.path.join(dir,'/system/fonts/DroidSansMono.ttf')
xxfile = os.path.join(dir, 'Download') + '/Crash.txt'
else:
xfontname='C:/Windows/Fonts/Courbd'
xxfile = os.path.join(os.path.expanduser("~"), "Downloads") + '\\Crash.txt'
xtfile = os.path.join(os.path.expanduser("~"), "Downloads") + '\\turtle.png'
xmode='W'
xbutsiz=.1,.1 #button size wid,hig
xbutxpos=.15
def get_widget_names(self):
xxx=[]
for widget in self.walk():
xxx.append(widget.name) #build the name list
return xxx #get_widget_names

def xtest(self):
self.ids.disp.text='Test!'
return #xtest

def read_color_codes(self):
#xcfile = 'c:/Users/danm9/Crash/colorcodes.txt'
xcfile = os.path.join(os.path.expanduser("~"), "Downloads") + '\\colorcodes.txt'
lookup_table = {}
with open(xcfile) as f:
for line in f:
#print('r',line)
key, value = line.strip('\n').split(" ")
lookup_table[key] = value
#print('k',key,value)
#print(lookup_table['255,000,000'])
return lookup_table #read_color_codes

def get_widget_colors(self):
#xlookup=self.read_color_codes()
#print(xlookup)
xxc=[]
for widget in self.walk():
#print(widget.name,end=' ',)
if hasattr(widget,'background_color'): #build the color list
x4=widget.background_color #s/b x,x,x,1
#print(x4)
for i in range(3): #fix 1,1,0,1 yellow
if x4[i]==1:
x4[i]=255

#print(x4[0],x4[1],x4[2],end=' ',)
x5=(int(x4[0]),int(x4[1]),int(x4[2]))
#print(x5,end=' ',)
x5=rgb_to_name(x5)
#print(x5)
else:
x5='white'
xxc.append(x5)
return xxc #get_widget_colors
def Listsizes(self,xf): #0=list, 1=file
print('listsizes')
lxx = ' ----pos- --size-- ------ hints ------\n'
lxx = lxx+' acr up wid hig parnt posx posy sizx sizy color\n'
# xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
xxx = self.get_widget_names()
xxx.remove('Main')
xxc = self.get_widget_colors()
#print(xxc)
xxc.remove('white')
#print(xxc)
xparent = [self.ids[idx].parent.name for idx in xxx] #
xppos = [self.ids[idx].parent.pos for idx in xxx]
xpsiz = [self.ids[idx].parent.size for idx in xxx]
xpos = [self.ids[idx].pos for idx in xxx]
xsiz = [self.ids[idx].size for idx in xxx]
#main requires seperate approach
lxx = lxx + self.pull_out(' main', self.pos, self.size,' ',(0,0),(0,0),'')
i=0
for x in xxx:
# pass in tuples and parent
lxx=lxx+' '+self.pull_out(x,xpos[i],xsiz[i],xparent[i],xppos[i],xpsiz[i],xxc[i])
i+=1
if xf==1:
file1 = open(self.xxfile,'w+')
lxx=lxx+"In file "+self.xxfile
file1.write(lxx)
#print(self.ids.disp.color)
#print(lxx)
#print('disp',self.ids.disp.text)
self.ids.disp.color='yellow'
#self.ids.disp.pos=(0,90)
self.ids.disp.text = lxx
#self.ids.disp.pos=(0,0)
return #listsizes

def pull_out(self,xname,x_pos, x_siz,x_parent,x_ppos,x_psiz,x_color):
#dont need to use unpack as cannot unpack scatter
x1, xx1 = x_pos[0],x_ppos[0]
y1, xy1 = x_pos[1],x_ppos[1]
x2, xx2 = x_siz[0],x_psiz[0]
y2, xy2 = x_siz[1],x_psiz[1]
xr="{0:5.0f}{1:5.0f} {2:5.0f}{3:5.0f}"
xy=xr.format(x1,y1,x2,y2)
xy=xname+xy #add name of widget to beginneing of line
xy=xy+' ' +x_parent
if xname==" main":
#preserve values for calculating hints - nothing to output for main
global xarc,xup,xwid,xhig,m_wid,m_hig
xarc, xup, xwid, xhig = x1,y1,x2,y2
m_wid, m_hig = xwid, xhig
else:
#calculate hints
xy=xy+' '+self.calc_pos_size(x1,y1,x2,y2,xx1,xy1,xx2,xy2)
xy=xy+' '+x_color+'\n'
return xy #pull_out
def calc_pos_size(self,acr,up,wid,hig,p_acr,p_up,p_wid,p_hig):
pos_x= 0 if acr == 0 else acr/p_wid
pos_y= 0 if up == 0 else up/p_hig
siz_x= wid/p_wid
siz_y= hig/p_hig
xr="{0:4.2f} {1:4.2f} {2:4.2f} {3:4.2f}"
xy=xr.format(pos_x,pos_y,siz_x,siz_y)
return xy #calc_pos_size
def set_focus(self):
if platform == "win":
self.ids.txti.focus = True
return #set_focus

def set_mode(self):
if self.xmode=="A":
return
if self.xmode=="E":
#switch to Windows mode
Window.size= (800,600)
self.ids.disp.font_size = 14
self.xmode = "W"
self.xltxt='W'
else:
#switch to Emulate mode
self.xresize = 4.2
x=self.xresize
Window.size = (1080 / x, 2340 / x) # 1080x2340 samsung s23 result 257x557
self.ids.disp.font_size = self.width/100
self.xmode='E'
self.xltxt='E'
self.ids.mode.text='Mode\n '+self.xmode
return #set_mode

def clear_it(self):
#self.ids.helo.text=''
self.ids.disp.text=''
self.ids.txti.text=''
self.set_focus()
return #clear_it

def drawit(self):
self.ids.draw.color='black'
self.ids.draw.text = "Only 1 Draw \nPer Session" #draw
self.ids.draw.disabled=True
#x=self.ids.disp.color
#for i in range(3): #fix color code 1,1,0,1
# if x[i] == 1:
# x[i] = 255
#print('x',x)
#self.ids.disp.color= x
self.Listsizes(0)
#print(2,self.ids.disp.text,self.ids.disp.color)

self.turtle_it() #call my turtle routine

return #drawit

def turtle_it(self):
import turtle
from turtle import Screen

t = turtle.Turtle()
s = Screen()
#s.setup(950, 750, 1360, 0) # pushes turtle screen to monitor 1
s.setup(950,750,0,0) #monitor 0
turtle.bgcolor('black')
t.speed(10)
t.turtlesize(.5,.5,.5)
t.penup()
t.pencolor('white') #axis lines are white
t.goto(-400,0)
t.pendown()
xz=-400 #draw x axis (horizontal)
for i in range(8):
t.fd(100)
t.stamp()
zz=-0 #write horizontal py/turtle tickmarks
for i in range(9):
t.penup()
t.goto(xz,-15)
t.pendown()
t.write(' '+str(zz)+' : '+str(xz))
t.penup()
t.goto(xz,-15)
t.pendown()
xz=xz+100
zz=zz+100

#setup for y axis (vertical)
t.penup()
t.goto(0,-300)
t.pendown()
t.lt(90)
xz=-300
zz=0
for i in range(6): #draw y axis (vertical)
t.write(' '+str(zz)+' : '+str(xz))
xz=xz+100
zz=zz+100
t.fd(100)
t.stamp()
t.write(' '+str(zz)+' : '+str(xz)) #last tickmark
self.xboxes=2
xxx=self.get_widget_names()
xxx.remove('Main')
xcolor=self.get_widget_colors()
xcolor.remove('white')
xpos = [self.ids[idx].pos for idx in xxx] #
xsiz = [self.ids[idx].size for idx in xxx] #
xnam = [self.ids[idx].name for idx in xxx] #

i=0 #index number from pos, size
for x in xxx: #run through widget names
x1 = xpos[i] #break out x and y values for pos
xx1=x1[0]
xy1=x1[1]
x2 = xsiz[i] #break out x and y values for size
xx2=x2[0]
xy2=x2[1]
self.drawbox(xx1,xy1,xx2,xy2,xcolor[i],xnam[i]) #draw the box
i+=1 #increment for next widget

t.penup() #put warning on top of drawing
t.goto(-300,325)
t.write('Close this screen to continue - Output saved in <downloads> turtle.png',font=('Arial', 14, 'normal'))
#turtle.Screen().bye()
# Get the turtle canvas
canvas = turtle.getcanvas()

# Get the bounding box of the turtle canvas
x0 = canvas.winfo_rootx()
y0 = canvas.winfo_rooty()
x1 = x0 + canvas.winfo_width()
y1 = y0 + canvas.winfo_height()-50

# Grab the image of the turtle canvas
image = ImageGrab.grab(bbox=(x0, y0, x1, y1))

# Save the image as a PNG file
image.save(self.xtfile)

#turtle.Screen().exitonclick()
turtle.done()
self.set_focus()
return #turtle_it

def drawbox(self, x0,y0,wid,hig,color,widg):
if self.xboxes==2:
#convert python to turtle
if x0==0: # labl,txti,floa,disp,helo
xx0=-400 #ok titl,txti,floa,disp,helo
else:
if x0>400: # clea,mode,draw,test
xx0=x0-400 #ok clea,mode,draw,test
else:
xx0=x0-400 #lfil,scat

if y0==0: # disp,helo
yy0=-300+hig #ok disp,helo
else:
if y0 > 300: # titl,txti,lsiz,lfil,clea,mode,draw,test,scat
yy0=y0-300+hig #ok titl,txti,lsiz,lfil,clea,mode,draw,test,scat
else:
yy0=y0-300+hig # floa,test
#ok floa

import turtle #draw a box
t=turtle.Turtle()
t.turtlesize(.5,.5,.5)
t.speed(30)
t.penup()
t.goto(xx0+(wid/2)-40,yy0-40) #put text inside box
t.pencolor(color)
t.write(' '+widg+': py='+str(int(x0))+' '+str(int(y0))+' '+str(int(wid))+' '+str(int(hig))
+ '\n tu='+str(int(xx0))+' '+str(int(yy0))
,font=('Arial', 10, 'normal'))
t.goto(xx0,yy0)
t.pencolor(color)
t.pendown()
t.fd(wid)
t.rt(90)
t.fd(hig)
t.rt(90)
t.fd(wid)
t.rt(90)
t.fd(hig)

class TutorialApp(App):
xturtled = 0
def build(self):
return ScatterTextWidget()

def _reposition(self):
#self.root.ids.scat.center = self.root.ids.floa.center
pass
if __name__ == "__main__":
TutorialApp().run()

elli...@cox.net

unread,
Aug 16, 2023, 10:00:28 AM8/16/23
to kivy-...@googlegroups.com

.

  • Your Scatter object is unsized and filling the screen, so the clicks are being “eaten” by the scatter, and not the buttons.  To fix this size your scatter object.  To see problems like these use the inspector tool.  This is a great tool for debugging layout issues.  See: https://kivy.org/doc/stable/api-kivy.modules.html#module-kivy.modules
    • > Python myapp.py -m inspector
    • They type cntrl-e, and click on the widget you want to inspect.
    • Play with the tool – you can get a lot of insight by looking into the widgets, clock the buttons.
  • In scatter, in the kv code you are using on_touch_up, use this with care.  In general, overload this from python
  • I would not recommend using a floatlayout here.  A floatlayout make you do all of the work manually.  The layouts are tools for sizing and positioning widgets.  The list of buttons can go in a BoxLayout (horizontal) the other widgets can go in a vertical BoxLayout.  If you nest these layouts – the layout can be used to position and size the widgets.
  • Something to try: Size and position the scatter so it matches the size of the label, make the label the size of the text (texture_size)

 

I did a quick hack below,  sizing the scatter to the lower half of the screen, and commenting out a few things so the code would run with out having to install anything.

 

'scat'
           
size_hint: None, None
           
size: root.width, root.height/2
           
gid: scat
           
on_touch_up: root.set_focus()
           
#pos: 200,200
           
background_color: 0,255,0,1   #'lime'

           
Label:      #hello
               
id: helo
                
size_hint: None, None
               
size: self.texture_size
                name
: 'helo'
               
text: "Hello!"
               
#font_size: '90sp'
               
font_size: 50
               
#pos_hint: {'center_x':.5, 'center_y':.6}
               
pos: 350,345
               
color: 'teal'
               
background_color: 0,128,128,1     #'teal'

       
Button:
           
id:lsiz
           
name: 'lsiz'
           
text: " Press\n    to\ndisplay"
           
on_press: root.Listsizes(0)
           
on_release: root.set_focus()
           
size_hint_y: None
           
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos, 'top':.80}
           
background_color: 0,255,0,1        #green
           
color: 'black'

       
Button:     #list sizes to file
           
id: lfil
           
name: 'lfil'
           
text: "Press\n  to\n file"
           
on_press: root.Listsizes(1)
           
on_release: root.set_focus()
           
size_hint_y: None
            
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos*2, 'top':.80}
           
background_color: 0,0,255,1   #blue
           
color: 'black'

       
Button:     #clear
           
id: clea
           
name: 'clea'
           
text: 'Clear'
           
on_press: disp  .text=''
           
on_release: root.clear_it()
           
size_hint_y: None
           
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos*3, 'top':.80}
           
background_color: 255,0,0,1   #red
            
color: 'black'

       
Button#mode
           
id: mode
            name
: 'mode'
           
text: 'Mode\n  '+root.xmode
           
on_press: root.set_mode()
           
on_release: root.set_focus()
           
size_hint_y: None
           
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos*4, 'top':.80}
           
background_color: 255,255,0,#yellow
           
color: 'black'

       
Button:     #draw
           
id: draw
           
name: 'draw'
           
text: "Draw"
           
on_press: root.drawit()
           
on_release: root.set_focus()
           
size_hint_y: None
           
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos*5, 'top':.80}
           
background_color: 128,0,128,1   #'purple'
           
color: 'black'

       
Button#xtest
           
id: test
           
name: 'test'
           
on_press: root.xtest()
           
text: 'xtest'
           
size_hint_y: None
           
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos*6, 'top':.80}
           
background_color: 128,128,128,1     #'maroon'
           
color: 'black'

--
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/3e1da8a8-39f7-46d6-9be1-ad0d5b63f608n%40googlegroups.com.

elli...@cox.net

unread,
Aug 16, 2023, 5:53:12 PM8/16/23
to kivy-...@googlegroups.com

I updated the kv code.  The layout changes here break functionality, but I’m sure you can fix that quickly.  I added some comments to the kv, I hope this is helpful.  Happy to answer any questions.

 

#:kivy 1.0.9

<ScatterTextWidget>:  # BoxLayout
   
orientation: 'vertical'
   
id: 'Main'
   
name: 'Main'

   
AnchorLayout# use to center the row of buttons
       
BoxLayout: # hold the row of buttons in a horizontal layout
           
size_hint_y: None
           
height: dp(70# set the height of the buttons
           
spacing: dp(5# set spacing between the buttons
           
padding: dp(5# padding around the outside of the buttons
           
Button:
               
id:lsiz
                name:
'lsiz'
               
text: " Press\n    to\ndisplay"
               
on_press: root.Listsizes(0)
               
on_release: root.set_focus()
               
background_color: 0,255,0,1        #green
               
color: 'black'

           
Button:     #list sizes to file
               
id: lfil
                name:
'lfil'
               
text: "Press\n  to\n file"
               
on_press: root.Listsizes(1)
               
on_release: root.set_focus()
               
background_color: 0,0,255,1   #blue
               
color: 'black'

           
Button:     #clear
               
id: clea
                name:
'clea'
               
text: 'Clear'
               
on_press: disp  .text=''
               
on_release: root.clear_it()
               
background_color: 255,0,0,1   #red
               
color: 'black'

           
Button#mode
               
id: mode
                name:
'mode'
                
text: 'Mode\n  '+root.xmode
               
on_press: root.set_mode()
               
on_release: root.set_focus()
               
background_color: 255,255,0,#yellow
               
color: 'black'

           
Button:     #draw
                
id: draw
                name:
'draw'
               
text: "Draw"
               
on_press: root.drawit()
               
on_release: root.set_focus()
               
background_color: 128,0,128,1   #'purple'
               
color: 'black'

            
Button#xtest
               
id: test
                name:
'test'
               
on_press: root.xtest()
               
text: 'xtest'
               
background_color: 128,128,128,1     #'maroon'
               
color: 'black'


   
Label:
       
id: titl
        name:
'titl'
       
text: 'Enter Text - Version: '+kivy.platform
       
size_hint_y: None
       
height: dp(50)
       
font_size: sp(20)
       
background_color: 0,0,128,1 #'navy'

   
TextInput:
       
id: txti
        name:
'txti'
       
size_hint_y: None
       
height: dp(50)
       
font_size: '25sp'
       
focus: True
       
on_text: helo.text = self.text  #change helo to match txti entered
        #background_color:
        #color: 255,0,0,1  #red


   
Label:       #widget display text
       
size_hint_y: # use size hint to set large area for text
       
id: disp
        name:
'disp'
       
text: 'disp'    #root.xltxt
       
font_name: root.xfontname
       
font_size: 14
       
background_color: 255,255,0,#yellow

   
RelativeLayout:
       
id: rel
       
size_hint: None, None  # use a relative layout so the position of the scatter widget is honored
       
size: 0, 0             # make the size zero so the Layout does not take any space
       
Scatter:
           
id: scat
            name:
'scat'
           
size_hint: None, None
           
size: helo.texture_size    # make the Scatter the same size as the text "Hello!"
           
pos: disp.center_x - helo.width/2, disp.center_y
            background_color
: 0,255,0,1   #'lime'

           
Label:      #hello
               
id: helo
               
size_hint: None, None
               
size: scat.size
               
name: 'helo'
               
text: "Hello!"
               
font_size: 50
                
color: 'teal'
               
background_color: 0,128,128,1     #'teal'

 

 

 

From: elli...@cox.net <elli...@cox.net>
Sent: Wednesday, August 16, 2023 7:00 AM
To: kivy-...@googlegroups.com
Subject: RE: [kivy-users] Scatter Widget problem

 

.

  • Your Scatter object is unsized and filling the screen, so the clicks are being “eaten” by the scatter, and not the buttons.  To fix this size your scatter object.  To see problems like these use the inspector tool.  This is a great tool for debugging layout issues.  See: https://kivy.org/doc/stable/api-kivy.modules.html#module-kivy.modules
    • > Python myapp.py -m inspector
    • They type cntrl-e, and click on the widget you want to inspect.
    • Play with the tool – you can get a lot of insight by looking into the widgets, clock the buttons.
  • In scatter, in the kv code you are using on_touch_up, use this with care.  In general, overload this from python
  • I would not recommend using a floatlayout here.  A floatlayout make you do all of the work manually.  The layouts are tools for sizing and positioning widgets.  The list of buttons can go in a BoxLayout (horizontal) the other widgets can go in a vertical BoxLayout.  If you nest these layouts – the layout can be used to position and size the widgets.
  • Something to try: Size and position the scatter so it matches the size of the label, make the label the size of the text (texture_size)

 

I did a quick hack below,  sizing the scatter to the lower half of the screen, and commenting out a few things so the code would run with out having to install anything.

 

#:kivy 1.0.9

'scat'
           
size_hint: None, None
           
size: root.width, root.height/2
           
gid: scat
           
on_touch_up: root.set_focus()
           
#pos: 200,200
           
background_color: 0,255,0,1   #'lime'

           
Label:      #hello
               
id: helo
                
size_hint: None, None
               
size: self.texture_size
                name
: 'helo'
               
text: "Hello!"
               
#font_size: '90sp'
               
font_size: 50
               
#pos_hint: {'center_x':.5, 'center_y':.6}
               
pos: 350,345
               
color: 'teal'
               
background_color: 0,128,128,1     #'teal'

       
Button:
           
id:lsiz
           
name: 'lsiz'
           
text: " Press\n    to\ndisplay"
           
on_press: root.Listsizes(0)
           
on_release: root.set_focus()
           
size_hint_y: None
           
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos, 'top':.80}
           
background_color: 0,255,0,1        #green
           
color: 'black'

       
Button:     #list sizes to file
           
id: lfil
           
name: 'lfil'
           
text: "Press\n  to\n file"
           
on_press: root.Listsizes(1)
           
on_release: root.set_focus()
           
size_hint_y: None
            
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos*2, 'top':.80}
           
background_color: 0,0,255,1   #blue
           
color: 'black'

       
Button:     #clear
           
id: clea
           
name: 'clea'
           
text: 'Clear'
           
on_press: disp  .text=''
           
on_release: root.clear_it()
           
size_hint_y: None
           
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos*3, 'top':.80}
           
background_color: 255,0,0,1   #red
            
color: 'black'

       
Button#mode
           
id: mode
            name
: 'mode'
           
text: 'Mode\n  '+root.xmode
           
on_press: root.set_mode()
           
on_release: root.set_focus()
           
size_hint_y: None
           
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos*4, 'top':.80}
           
background_color: 255,255,0,#yellow
           
color: 'black'

       
Button:     #draw
           
id: draw
           
name: 'draw'
           
text: "Draw"
           
on_press: root.drawit()
           
on_release: root.set_focus()
           
size_hint_y: None
           
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos*5, 'top':.80}
           
background_color: 128,0,128,1   #'purple'
           
color: 'black'

       
Button#xtest
           
id: test
           
name: 'test'
           
on_press: root.xtest()
           
text: 'xtest'
           
size_hint_y: None
           
size_hint: root.xbutsiz
           
pos_hint: {'x':root.xbutxpos*6, 'top':.80}
           
background_color: 128,128,128,1     #'maroon'
           
color: 'black'

 

 

 

 

 

 

From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> On Behalf Of Dan Moormann


Sent: Tuesday, August 15, 2023 8:36 PM
To: Kivy users support <kivy-...@googlegroups.com>
Subject: [kivy-users] Scatter Widget problem

 

I've been using the Scatter widget tutorial as a launch pad to learn python/kivy/kv.  I've added a lot of stuff to the original program and have made a lot of changes.  Most noticeably I've added buttons to learn more about size and position.  This includes a display and drawing of the widgets (using turtle).  I've recently reordered the widgets and placed most of them in a FloatLayout in order to get absolute positioning.  This seems to work.

--

Dan Moormann

unread,
Aug 16, 2023, 9:15:40 PM8/16/23
to kivy-...@googlegroups.com
Thanks again Eliot.  I think I understand what you said and I will experiment with it in the next couple days.

Dan Moormann

unread,
Aug 20, 2023, 10:57:20 PM8/20/23
to kivy-...@googlegroups.com
Eliot - I took a look at inspector.  A bit overwhelming.  I'm not sure how or when I might need it, but thanks for suggesting it.

elli...@cox.net

unread,
Aug 21, 2023, 11:31:16 AM8/21/23
to kivy-...@googlegroups.com

I have found the Inspector is very useful when you are trying to debug issues with layouts.

Reply all
Reply to author
Forward
0 new messages