Tom Fuller Tom Fuller - 1 year ago 122
Python Question

I can't seem to open two windows with python, tkinter

I am getting an error trying to open a window in python

I am using

so the code looks a bit like this

from tkinter import *
Window = Tk()
Window2 = Tk()
Window.create_rectangle(0, 0, 100, 100) # border
Window2.create_rectangle(0, 0, 100, 100)

Answer Source

You have some basic typos / syntax errors in your code. But anyway...

A Tkinter window doesn't have create_rectangle method. However, the Canvas widget does have that method; you can use it like this.

import tkinter as tk

window = tk.Tk()
canvas = tk.Canvas(window, width=100, height=100)
canvas.create_rectangle(1, 1, 99, 99, outline="blue", fill="white") 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download