Home > Blockchain >  Tkinter window not opening in pycharm
Tkinter window not opening in pycharm

Time:12-16

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

CodePudding user response:

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
  • Related