import tkinter as tk
def main():
root = tk.Tk()
window1 = Window(root, "hello", "500x500")
Button(root, "Click me", 2, 2, 10, 5)
root.mainloop()
class Window:
def __init__(self, root, title, geometry):
self.root = root
root.title(title)
root.geometry(geometry)
class Button:
def __init__(self, parent, message, row, column, width, height,):
self.message = message
self.row = row
self.column = column
self.width = width
self.height = height
tk.Button(parent, text=message, height=height, width=width).grid(column=column,
row=row)
if __name__ == '__main__':
main()
When I run the program the button is being placed at y=0 and x=0 but I have no clue why? Can anyone yell me why or give some suggestions.
CodePudding user response:
This line
tk.Button(parent, text=message, height=height, width=width).grid(column=column, row=row)
change with this:
tk.Button(parent, text=message, height=height, width=width).grid(padx=column, pady=row)
or
tk.Button(parent, text=message, height=height, width=width).place(x=column, y=row)