'trying to set halignment to label text in a python file
i am trying to set halign for label text created in python file. the alignment not working as i want. after applying the setting below that i commented out, it aligns the text in the label, but the text didnt use the whole width of the label. like it reduced the label width or text compressed and text that's suppose to be one line now take 3 lines. what am i doing wrong? python file
def on_pre_enter(self, *args):
bxx = BoxLayout(orientation="horizontal", size_hint=(1, None), size=(1, 30))
lbx1 = Label()
lbx1.size_hint_x = .8
lbx2 = Label(text="Product", font_size=20, color=(0,0,1), size_hint_x=2)
lbx3 = Label(text="Quantity", font_size=20, color=(0, 0, 1))
#lbx3.text_size = lbx3.size
#lbx3.halign = "left"
#lbx3.valign = "middle"
lbx4 = Label(text="Price", font_size=20, color=(0, 0, 1))
#lbx4.text_size = lbx4.size
#lbx4.halign = "right"
#lbx4.valign = "middle"
lbx5 = Label()
lbx5.size_hint_x=.8
bxx.add_widget(lbx1)
bxx.add_widget(lbx2)
bxx.add_widget(lbx3)
bxx.add_widget(lbx4)
bxx.add_widget(lbx5)
self.ids.rcp.add_widget(bxx)
for i in range(len(wk.Forsales.slpr)):
blt = BoxLayout(orientation="horizontal", size_hint=(1, None), size=(1,30))
lt1 = Label()
lt1.size_hint_x= .8
lt2 = Label(text=(wk.Forsales.slpr[i]), font_size=12, color=(0, 0, 1),
size_hint_x=2)
#lt2.text_size = lt2.size
#lt2.halign = "left"
#lt2.valign = "middle"
lt3 = Label(text=str(wk.Forsales.slqtyn[i]) + " " + str(wk.Forsales.slqtyw[i]),
font_size=12, color=(0, 0, 1))
#lt3.text_size = lt3.size
#lt3.halign = "left"
#lt3.valign = "middle"
lt4 = Label(text="{:,.2f}".format(wk.Forsales.slp[i]), font_size=12, color=(0, 0,
1))
#lt4.text_size = lt4.size
#lt4.halign = "right"
#lt4.valign = "middle"
lt5 = Label()
lt5.size_hint_x=.8
blt.add_widget(lt1)
blt.add_widget(lt2)
blt.add_widget(lt3)
blt.add_widget(lt4)
blt.add_widget(lt5)
self.ids.rcp.add_widget(blt)
bxb = BoxLayout(orientation="horizontal", size_hint=(1, None), size=(1, 30))
lxb1 = Label()
lxb1.size_hint_x=.8
lxb2 = Label(text="", font_size=20, color=(0, 0, 1), size_hint_x=2)
lxb3 = Label(text="Total", font_size=20, color=(0, 0, 1))
lxb4 = Label(text="{:,.2f}".format(sum(wk.Forsales.slp)), font_size=20, color=(0,
0, 1))
#lxb4.text_size = lxb4.size
#lxb4.halign = "right"
#lxb4.valign = "middle"
lxb5 = Label()
lxb5.size_hint_x=.8
bxb.add_widget(lxb1)
bxb.add_widget(lxb2)
bxb.add_widget(lxb3)
bxb.add_widget(lxb4)
bxb.add_widget(lxb5)
self.ids.rcp.add_widget(bxb)
bbb = BoxLayout(orientation="horizontal", size_hint=(1, None), size=(1, 30))
self.ids.rcp.add_widget(bbb)
bbx = BoxLayout(orientation="horizontal", size_hint=(1, None), size=(1, 30))
lx1 = Label()
lx1.size_hint_x= .8
lx2 = Label(text="Seller's Signature", font_size=15, color=(0, 0, 1), size_hint_x=2)
lx3 = Label(text="", font_size=20, color=(0, 0, 1))
lx4 = Label(text="Buyer's Signature", font_size=15, color=(0, 0, 1))
lx5 = Label()
lx5.size_hint_x=.8
bbx.add_widget(lx1)
bbx.add_widget(lx2)
bbx.add_widget(lx3)
bbx.add_widget(lx4)
bbx.add_widget(lx5)
self.ids.rcp.add_widget(bbx)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
