-1

It seems that I explained my problem very terribly, but I have a problem with the grid function on my label. The label does show up but, I cant change the row/column of it or do any function inside of the brackets.

I put the code of how to replicate the problem there. Putting anything inside of the .grid() brackets does nothing as stated earlier

from tkinter import *
root = Tk()

#To actually see that it does not work
root.geometry("800x600")

Var = StringVar()

Label = Label(root, textvariable=Var)

#Location of problem, adding stuff into the brackets does not change anything. For example: sticky = "ne"
Label.grid()

Var.set("Ha")

root.mainloop()
Grusen
  • 31
  • 4
  • 2
    What does "won't work" mean? And please include a [mcve] in the question. Links to code on other sites is strongly discouraged here. – Bryan Oakley Aug 20 '18 at 15:37
  • Your code seems to work fine for me. I see a label appear with the string "Ha". – Bryan Oakley Aug 20 '18 at 17:41
  • Can you be more specific about what you're trying to do. Also, have you searched other questions? Are you aware that rows and columns by default are only as wide and tall as necessary to hold their contents, and that rows and columns that are empty have a size of zero? – Bryan Oakley Aug 20 '18 at 17:42

1 Answers1

0

To get the label to show up on the right side, you can specify the number of columns in the grid and then place the label in the last column. For example, try adding this just after your "#Location of problem" comment:

cols = 0
while cols < 4:
    root.columnconfigure(cols, weight=1)
    cols += 1
Label.grid(column=3)
screenpaver
  • 1,120
  • 8
  • 14
  • Im quite new to tkinter and have not seen the "columnconfigure" command in use. How come that loop specifies the number of columns? Is it possible to do the same to make rows? Finnaly, why does the .grid() way to do it not work with a label using StringVar? – Grusen Aug 22 '18 at 14:35
  • It all depends on what you want to do. If you know you will have a certain grid pattern (rows x columns) then you can do like above (including rows in a similar fashion) to lay it out. If you just want a specified label cell width and label placement in that cell you could just do something like: `label1 = Label(root, textvariable=Var, width=100, anchor=E)` followed by `label1.grid()`. – screenpaver Aug 22 '18 at 16:39