Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tkinter window not opening in pycharm

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading