Answers for "how to make a window in python"

2

how to make a window in python

import tkinter
from tkinter import *

#this makes the window
window = Tk()
#title
window.title("My Window")
#change the size to whatever you want too
window.configure(width = 800, height = 800)
#change the background color to whatever you want too
window.configure(bg = 'black')
#this runs the window
window.mainloop()

#simple way to a window in python
Posted by: Guest on August-05-2021
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
2

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
-1

how to make a screen in python

import pygame
pygame.init()

sh = int(500)
sw = int(500)
win = pygame.display.set_mode((sh, sw))

run = True
while run:
    pygame.time.delay(100)
	for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
Posted by: Guest on May-08-2020

Code answers related to "how to make a window in python"

Python Answers by Framework

Browse Popular Code Answers by Language