#If using tkinter import tkinter as tk from tkinter import* #Window creating root = tk.Tk() # Defining name name = "First window" # Setting window root.title(name) # IF want to use geometry So let me tell that no need of that at all # Tkinter sets the window according to data or things inside it # Adding button Button bt1 = Button(root, text = "Simple click"); # Making function def doer(): # Print is for console print("Did well"); # Adding button with function Button bt2 = Button(root, text = "Function", command = doer) # If you will add () it after brackets it will run automatically # Adding buttons bt1.pack() bt2.pack() root.mainloop() # This can show error If using pycharm reformat file # Set it as you are best
Here is what the above code is Doing:
1. First, we create a window.
2. Then, we create a button.
3. We create a function.
4. We create a button that calls the function.
5. We add the buttons to the window.
6. We start the window.