I make a simple GUI program:

enter image description here

Entry and Button objects that are next to each other must be three cells lower. How to do it? Here is the code itself:

from tkinter import * class Shell(Frame): def __init__(self, window): super().__init__(window) self.grid() self.__clicked = 0 self.__init_widgets() def __init_widgets(self): self.__lbl = Label(self, text = "Button clicked: " + str(self.__clicked)) self.__lbl.grid(row = 0, column = 0, columnspan = 2, sticky = W) self.__btn = Button(self, text = "Click on me", command = self.__clicker) self.__btn.grid(row = 0, column = 2, columnspan = 2, sticky = W) self.__ent = Entry(self) self.__ent.grid(row = 3, column = 0, columnspan = 2, sticky = W) self.__ent_button = Button(self, text = "Enter", command = self.__input_bold) self.__ent_button.grid(row = 3, column = 2, sticky = W) self.__fuck_label = Label(self, text = "Hey, bitch") self.__fuck_label.grid(row = 5, columnspan = 3) def __clicker(self): self.__clicked += 1 self.__lbl["text"] = "Button clicked: " + str(self.__clicked) def __input_bold(self): if self.__ent.get() == "Fuck you": self.__fuck_label["text"] = "O_0" else: self.__fuck_label["text"] = "What a fuck did you say?!" if __name__ == "__main__": main_window = Tk() main_window.title("Clicker") main_window.geometry("200x200") shell = Shell(main_window) main_window.mainloop() 

    1 answer 1

    In order to display empty lines, you can use the grid_rowconfigure method.

    Here is a simple example:

     from tkinter import Tk, Label root = Tk() root.geometry('200x200') label1 = Label(root, text="Label 1") label1.grid(row=0, column=0) root.grid_rowconfigure(1, weight=1) label2 = Label(root, text="Label 2") label2.grid(row=3, column=0) root.mainloop() 

    If in the example we comment out the root.grid_rowconfigure(2, weight=1) , then there will be no empty lines.