pythonfiletkintertkinter-canvas

The canvas' background color isn't changed


I have 2 seperate files and trying to make a sort of 'module' with this one file. But it does not work.

The background color is still this weird gray color even if I set it to say, black. Here is the 'module' file:

import tkinter as tk

class TUICanv:
    global screenWidth, screenHeight
    def __init__(self,win,bg="#232627"):
        self.screenWidth = win.winfo_screenwidth()
        self.screenHeight = win.winfo_screenheight()
        self.canvas = tk.Canvas(win,width=self.screenWidth,height=self.screenHeight,background=bg)
        self.background = bg
        self.width = self.canvas.winfo_width()
        self.height = self.canvas.winfo_height()

And here is the other file:

import tkinter as tk
import terkinter as tr
import os
import re

win = tk.Tk()
allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"
win.title("Terminos")
canv = tr.TUICanv(win)
win.geometry(f'{canv.screenWidth}x{canv.screenHeight}')
canv.canvas.create_text(100,10,fill="darkblue",font="Times 20 italic bold",text="Click the bubbles that are multiples of two.")

win.mainloop()

The background does not change. It may be that the window in the other file is different, because I have only started tkinter 2 weeks ago.


Solution

  • Your canvas is not visible. One way to make it visible is to pack it by by adding

    self.canvas.pack(fill="both", expand=True)
    

    to your terkinter.py __init__ method.