Answers for "how to use a window with python"

1

how to open a window in python

import tkinter as tk
 
 
def new_window1():
    " new window"
    try:
        if win1.state() == "normal": win1.focus()
    except NameError as e:
        print(e)
        win1 = tk.Toplevel()
        win1.geometry("300x300+500+200")
        win1["bg"] = "navy"
        lb = tk.Label(win1, text="Hello")
        lb.pack()
 
 
win = tk.Tk()
win.geometry("200x200+200+100")
button = tk.Button(win, text="Open new Window")
button['command'] = new_window1
button.pack()
win.mainloop()
Posted by: Guest on September-14-2020
3

Window in python

#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
Posted by: Guest on April-22-2021

Code answers related to "how to use a window with python"

Python Answers by Framework

Browse Popular Code Answers by Language