Tkinter window not opening in pycharm

Question:

I am eriting code in pycharm with tkinter but the window is not opening. May someone assist?
`

import tkinter
window = tkinter.Tk()
button = tkinter.Button(window, text="Do not press this button! >:-(", width=40)
button.pack(padx=10, pady=10)

`

i tried checking my script for bugs but nothing

Asked By: Ewan

||

Answers:

This has nothing to do with Pycharm, but with tkinter library and how to use it.

You are missing 2 important stuff:

  • Button is in ttk.py file inside tkinter library: from tkinter import ttk
  • Execute the whole script with mainloop

Try this:

import tkinter
from tkinter import ttk  # Import ttk file from tkinter library


window = tkinter.Tk()
window.title("Coolest title ever written")

button = ttk.Button(window, text="Do not press this button! >:-(", width=40)  # Use Button from the import ttk file
button.pack(padx=10, pady=10)

window.mainloop()  # Execute the whole script
Answered By: Asi
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.