Home > Blockchain >  How to use Python-Tkinter to open a blank window?
How to use Python-Tkinter to open a blank window?

Time:09-17

I am new to Python, so I don’t have any code that I tried or tested. Do any of know how to open a blank window that can be ran with Python? I’m aware this has probably been asked, however I couldn’t find it. Thank you.

CodePudding user response:

Using tkinter you can do this to open a blank window:

from tkinter import *

root = Tk()
root.title("Hello this is title")
root.geometry("500x300")

root.mainloop()

CodePudding user response:

Try this, should work fine:

import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red", command=self.master.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        print("hi there, everyone!")

root = tk.Tk()
app = Application(master=root)
app.mainloop()
  • Related