Каждый ряд приклеен к следующему - ткинтер - PullRequest
0 голосов
/ 21 апреля 2019

Я создаю графический интерфейс, и у меня проблема.Несмотря на то, что у меня есть, например, кнопки на row=17 и row=40, они прикреплены друг к другу.Например: серая кнопка в 17 ряду и кнопка Proceed в 40 ряду.Несмотря на это, это выглядит так:

enter image description here

Почему это так?Почему каждый ряд придерживается другого несмотря на ряд = 17 и ряд = 40.Почему между ними нет места?

Код выглядит следующим образом (эта строка = 17, а строка = 40 находится в конце кода):

gui = Tk()
gui.geometry('600x500')
gui.title("Vending Machine")

# gui.configure(background="white")
expression = ""
equation = StringVar()
expression_field = Entry(gui, textvariable=equation)
expression_field.grid(row=8, columnspan=4, ipadx=70)
equation.set('enter number of item')

labelOne = ttk.Label(gui, text='')
labelOne.grid(column=1, row=12)

labelTwo = ttk.Label(gui, text='')
labelTwo.grid(column=1, row=18)

labelThree = ttk.Label(gui, text='')
labelThree.grid(column=1, row=0)
labelThree.configure(text='Wpisz numer produktu!')


def dropCoin(value):
    labelTwo.configure(text='Wrzucono: {0:0.2f}'.format(container.howManyCoinsWereDropped(value)))


def getPriceOfGivenID():
    givenID = int(equation.get())
    labelOne.configure(text='Musisz wrzucić: ' + str(container.find_price_of_given_id(givenID)))


def press(num):
    global expression
    expression = expression + str(num)
    equation.set(expression)
    return expression


def clear():
    global expression
    expression = ""
    equation.set("")
    labelOne.configure(text='')


##### BUTTONS FOR GIVING ID
button1 = Button(gui, text=' 1 ', fg='black', bg='light blue',
                 command=lambda: press(1), height=1, width=7)
button1.grid(row=2, column=0)

button2 = Button(gui, text=' 2 ', fg='black', bg='light blue',
                 command=lambda: press(2), height=1, width=7)
button2.grid(row=2, column=1)

button3 = Button(gui, text=' 3 ', fg='black', bg='light blue',
                 command=lambda: press(3), height=1, width=7)
button3.grid(row=2, column=2)

button4 = Button(gui, text=' 4 ', fg='black', bg='light blue',
                 command=lambda: press(4), height=1, width=7)
button4.grid(row=3, column=0)

button5 = Button(gui, text=' 5 ', fg='black', bg='light blue',
                 command=lambda: press(5), height=1, width=7)
button5.grid(row=3, column=1)

button6 = Button(gui, text=' 6 ', fg='black', bg='light blue',
                 command=lambda: press(6), height=1, width=7)
button6.grid(row=3, column=2)

button7 = Button(gui, text=' 7 ', fg='black', bg='light blue',
                 command=lambda: press(7), height=1, width=7)
button7.grid(row=4, column=0)

button8 = Button(gui, text=' 8 ', fg='black', bg='light blue',
                 command=lambda: press(8), height=1, width=7)
button8.grid(row=4, column=1)

button9 = Button(gui, text=' 9 ', fg='black', bg='light blue',
                 command=lambda: press(9), height=1, width=7)
button9.grid(row=4, column=2)

button0 = Button(gui, text=' 0 ', fg='black', bg='light blue',
                 command=lambda: press(0), height=1, width=7)
button0.grid(row=5, column=1)

button10 = Button(gui, text=' Proceed ', fg='black', bg='red',
                  command=lambda: getPriceOfGivenID(), height=1, width=7)
button10.grid(row=10, column=1)

button11 = Button(gui, text=' Clear ', fg='black', bg='orange',
                  command=lambda: clear(), height=1, width=7)
button11.grid(row=10, column=2)

##BUTONS FOR DROPING COINS

Coin1 = Button(gui, text=' 0.01 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.01"), height=1, width=7)
Coin1.grid(row=15, column=0)

Coin2 = Button(gui, text=' 0.02 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.02"), height=1, width=7)
Coin2.grid(row=15, column=1)

Coin3 = Button(gui, text=' 0.05 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.05"), height=1, width=7)
Coin3.grid(row=15, column=2)

Coin4 = Button(gui, text=' 0.1 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.1"), height=1, width=7)
Coin4.grid(row=16, column=0)

Coin5 = Button(gui, text=' 0.2 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.2"), height=1, width=7)
Coin5.grid(row=16, column=1)

Coin6 = Button(gui, text=' 0.5 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.5"), height=1, width=7)
Coin6.grid(row=16, column=2)

Coin7 = Button(gui, text=' 1 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("1"), height=1, width=7)
Coin7.grid(row=17, column=0)

Coin8 = Button(gui, text=' 2 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("2"), height=1, width=7)
Coin8.grid(row=17, column=1)

Coin9 = Button(gui, text=' 5 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("5"), height=1, width=7)
Coin9.grid(row=17, column=2)

button11 = Button(gui, text=' Proceed ', fg='black', bg='red',
                  command=lambda: press(0), height=1, width=7)
button11.grid(row=40, column=1)

mainframe = ttk.Frame(gui)

1 Ответ

1 голос
/ 21 апреля 2019

Пустая строка не имеет высоты, пустой столбец не имеет ширины.

Если вы поставите пустой Widget с height= (т.е. пустым Frame или Label без текста), тогда строка будет иметь высоту, и вы увидите это как пустое пространство.

Используя gui.rowconfigure(row_number, minsize=...), вы можете установить минимальную высоту для одного ряда. Если вы делаете это в цикле for, вы можете установить его для всех строк.

enter image description here

Используя gui.columnconfigure(colum_number, minsize=...), вы можете установить минимальную ширину для одного столбца. Если вы делаете это в цикле for, вы можете установить его для всех столбцов.

Код:

from tkinter import *
from tkinter import ttk

gui = Tk()
gui.geometry('600x500')
gui.title("Vending Machine")

for x in range(150):
    gui.rowconfigure(x, minsize=10)

# gui.configure(background="white")
expression = ""
equation = StringVar()
expression_field = Entry(gui, textvariable=equation)
expression_field.grid(row=8, columnspan=4, ipadx=70)
equation.set('enter number of item')

labelOne = ttk.Label(gui, text='')
labelOne.grid(column=1, row=12)

labelTwo = ttk.Label(gui, text='')
labelTwo.grid(column=1, row=18)

labelThree = ttk.Label(gui, text='')
labelThree.grid(column=1, row=0)
labelThree.configure(text='Wpisz numer produktu!')


def dropCoin(value):
    labelTwo.configure(text='Wrzucono: {0:0.2f}'.format(container.howManyCoinsWereDropped(value)))


def getPriceOfGivenID():
    givenID = int(equation.get())
    labelOne.configure(text='Musisz wrzucić: ' + str(container.find_price_of_given_id(givenID)))


def press(num):
    global expression
    expression = expression + str(num)
    equation.set(expression)
    return expression


def clear():
    global expression
    expression = ""
    equation.set("")
    labelOne.configure(text='')


##### BUTTONS FOR GIVING ID
button1 = Button(gui, text=' 1 ', fg='black', bg='light blue',
                 command=lambda: press(1), height=1, width=7)
button1.grid(row=2, column=0)

button2 = Button(gui, text=' 2 ', fg='black', bg='light blue',
                 command=lambda: press(2), height=1, width=7)
button2.grid(row=2, column=1)

button3 = Button(gui, text=' 3 ', fg='black', bg='light blue',
                 command=lambda: press(3), height=1, width=7)
button3.grid(row=2, column=2)

button4 = Button(gui, text=' 4 ', fg='black', bg='light blue',
                 command=lambda: press(4), height=1, width=7)
button4.grid(row=3, column=0)

button5 = Button(gui, text=' 5 ', fg='black', bg='light blue',
                 command=lambda: press(5), height=1, width=7)
button5.grid(row=3, column=1)

button6 = Button(gui, text=' 6 ', fg='black', bg='light blue',
                 command=lambda: press(6), height=1, width=7)
button6.grid(row=3, column=2)

button7 = Button(gui, text=' 7 ', fg='black', bg='light blue',
                 command=lambda: press(7), height=1, width=7)
button7.grid(row=4, column=0)

button8 = Button(gui, text=' 8 ', fg='black', bg='light blue',
                 command=lambda: press(8), height=1, width=7)
button8.grid(row=4, column=1)

button9 = Button(gui, text=' 9 ', fg='black', bg='light blue',
                 command=lambda: press(9), height=1, width=7)
button9.grid(row=4, column=2)

button0 = Button(gui, text=' 0 ', fg='black', bg='light blue',
                 command=lambda: press(0), height=1, width=7)
button0.grid(row=5, column=1)

button10 = Button(gui, text=' Proceed ', fg='black', bg='red',
                  command=lambda: getPriceOfGivenID(), height=1, width=7)
button10.grid(row=10, column=1)

button11 = Button(gui, text=' Clear ', fg='black', bg='orange',
                  command=lambda: clear(), height=1, width=7)
button11.grid(row=10, column=2)

##BUTONS FOR DROPING COINS

Coin1 = Button(gui, text=' 0.01 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.01"), height=1, width=7)
Coin1.grid(row=15, column=0)

Coin2 = Button(gui, text=' 0.02 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.02"), height=1, width=7)
Coin2.grid(row=15, column=1)

Coin3 = Button(gui, text=' 0.05 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.05"), height=1, width=7)
Coin3.grid(row=15, column=2)

Coin4 = Button(gui, text=' 0.1 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.1"), height=1, width=7)
Coin4.grid(row=16, column=0)

Coin5 = Button(gui, text=' 0.2 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.2"), height=1, width=7)
Coin5.grid(row=16, column=1)

Coin6 = Button(gui, text=' 0.5 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("0.5"), height=1, width=7)
Coin6.grid(row=16, column=2)

Coin7 = Button(gui, text=' 1 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("1"), height=1, width=7)
Coin7.grid(row=17, column=0)

Coin8 = Button(gui, text=' 2 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("2"), height=1, width=7)
Coin8.grid(row=17, column=1)

Coin9 = Button(gui, text=' 5 ', fg='black', bg='seashell4',
               command=lambda: dropCoin("5"), height=1, width=7)
Coin9.grid(row=17, column=2)

button11 = Button(gui, text=' Proceed ', fg='black', bg='red',
                  command=lambda: press(0), height=1, width=7)
button11.grid(row=40, column=1)

mainframe = ttk.Frame(gui)

gui.mainloop()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...