1

This code showed me some random numbers on the right side on my screen.

from Tkinter import *
import math
from random import randrange

number=Tk()
number.geometry("1308x720")
number.config(bg="black")
ECG=randrange(0,1000);SP=randrange(0,1000);PLES=randrange(0,1000);show=randrange(0,1000)
c1=StringVar();c2=StringVar();c3=StringVar();c4=StringVar()
c1.set(ECG);c2.set(SP);c3.set(PLES);c4.set(show)
valor_c1=Label(number,textvariable=c1,width=int(c1.get())//10,height=1,fg="red",anchor="ne",bg="black").grid(row=0,column=2, sticky=E)
valor_c2=Label(number,textvariable=c2,width=int(c2.get())//10,height=1,fg="red",anchor="ne",bg="black").grid(row=0,column=2, sticky=E)
valor_c3=Label(number,textvariable=c3,width=int(c3.get())//10,height=1,fg="red",anchor="ne",bg="black").grid(row=0,column=2, sticky=E)
valor_c4=Label(number,textvariable=c4,width=int(c4.get())//10,height=1,fg="red",anchor="ne",bg="black").grid(row=0,column=2, sticky=E)
number.grid_columnconfigure(2, weight=1)
number.mainloop()

Now I need to separate the second number 4,5 cm away from the edge, the third number 9 cm away from the edge and the fourth number 13,5 cm away from the edge. I tried to separate one number of the other changing the number of row, but did not work To summarizing, my question is: ¿How to separate one number of the other?

1 Answer 1

1

Use pady or ipady option. See Tkinter.Grid.grid.

Label(number,textvariable=c1,width=int(c1.get())//10,height=1,fg="red",anchor="ne",bg="green").grid(row=0,column=2, sticky=E, pady=10)
Label(number,textvariable=c2,width=int(c2.get())//10,height=1,fg="blue",anchor="ne",bg="snow").grid(row=4,column=2, sticky=E, pady=10)
Label(number,textvariable=c3,width=int(c3.get())//10,height=1,fg="cyan",anchor="ne",bg="grey").grid(row=8,column=2, sticky=E, pady=10)
Label(number,textvariable=c4,width=int(c4.get())//10,height=1,fg="gold",anchor="ne",bg="blue").grid(row=16,column=2, sticky=E, pady=10)
#                                                                                                                              ^^^^^^^

BTW, you can specify the padding as pixel, not as cm.

enter image description here

2
  • Thank you I was trying with pady and ipady but my mistake was that i did not pass of 5. I solved my problem putting a pady over 80 in the second and fourth label. Thank you so much.
    – rpi-uts
    Feb 17, 2014 at 16:34
  • I am going to post a new question about how to combine a pygame program with this code.
    – rpi-uts
    Feb 17, 2014 at 16:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.