Justification for a label in code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • themadtux
    New Member
    • Mar 2020
    • 1

    Justification for a label in code

    Quick question, I have a label that is counting the letters that are typed in a textbox. But what I do want with that label is that I need it to be right justified. If I set the properties of the label to have right align it doesn't seem to work. So do I need to align it in the code so when it hits double digits it doesn't run over the item to the right but just expands to the left... How can I justify the label via code?

    Here's the code I'm using for the label...

    Code:
    Dim a As Object
    a = Len(Me.tbImperial.Text)
    lblImperialCount.Text = (1 + a)
    Adding "lblImperialCou nt.TextAlign = ContentAlignmen t.MiddleRight" to it doesn't seem to make a difference either...

    I hope I am clear enough with my questions :)

    Thanks
  • MerlinTheGreat
    New Member
    • Jun 2022
    • 6

    #2
    A label has no Text property, but a Caption property.
    Your code should read:
    Code:
    Dim a As Object
    a = Len(Me.tbImperial.Text)
    lblImperialCount.[B]Caption[/B] = (1 + a)

    Comment

    • webapp
      New Member
      • Apr 2022
      • 2

      #3
      Tkinter Label widgets are used to add images and create text in a particular application. There are various functions and methods available in the library which can be used to style the widgets and its property. In order to justify the text in the label widget, we can use the justify property. It is generally used to justify the position or the alignment of the text such as RIGHT, LEFT, and CENTER.

      Example
      In this application, we will justify the position of a text label using the justify property.

      #Import tkinter library
      from tkinter import *
      #Create an instance of tkinter frame or window
      win= Tk()
      #Set the geometry of tkinter frame
      win.geometry("7 50x350")
      #Crate a Label widget
      label1= Label(win, text="Box1")
      label1.pack()
      label2= Label(win, text= "\nKeep\nLearni ng", bd=1, relief= "solid",fon t= ("Helvetica 20"), justify= RIGHT)
      label2.pack()
      Label(win, text= "Box2").pac k()
      label3= Label(win, text="\nLearnin g\nMakes\nPerfe ct", bd=1, relief="solid", font=('Helvetic a 20'), justify= LEFT)
      label3.pack()
      win.mainloop()
      Last edited by Niheel; Jun 23 '22, 08:35 AM. Reason: link removed, add your link to your profile, thanks

      Comment

      Working...