Montague27 Montague27 - 1 year ago 65
Python Question

Python can't add canvas to ttk notebook page

from tkinter import *
from tkinter import ttk

class MainGame(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent

def initUI(self):
global canvas
# ===Part A ===
self.pack(fill = BOTH, expand = 1) = ttk.Notebook(self, width = 650 ,height = 630)
self.page1 = ttk.Frame(self), text = 'Tab1') = 1, anchor = 'nw', side = 'top')
# ===Part B ===
canvas = Canvas(self)
canvas.create_rectangle([10,10, 650,630], fill = 'blue')
canvas.pack(fill = BOTH, expand = 1)
self.a = Label(self, text = 'Haha'),y=50)

root = Tk()
main = MainGame(root)

How can I add my rectangle into ttk's notebook? I found that my rectangle is always created below the notebook, but this situation is not the same with

I want to put the rectangle inside the notebook, should I add something to

Answer Source

If you want the canvas to be in the notebook, you must add it to one of the notebook pages. For example, if you want it in, you would change this line:

canvas = Canvas(self)

... to this:

canvas = Canvas(self.page1)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download