简体   繁体   中英

Background Colour - Tkinter

Trying to change the background of the whole canvas, this is my code:

import tkinter as tk
root = tk.Tk()
screen = tk.Canvas(root)
screen.grid()


    class Digit:
        def __init__(self, canvas, x=10, y=10, length=20, width=4, background='cyan'):
            self.canvas = canvas
            l = length
            self.segs = []
            for x0, y0, x1, y1 in offsets:
                self.segs.append(canvas.create_line(
                    x + x0*l, y + y0*l, x + x1*l, y + y1*l,
                    width=width, state = 'hidden'))
        def show(self, num):
            for iid, on in zip(self.segs, digits[num]):
                self.canvas.itemconfigure(iid, state = 'normal' if on else 'hidden')

I've have tried putting the defining the background colour in different places, however nothing will change the colour. I have tried defining the background in the canvas.create.line but still had no luck. I also had it defined as root.configure(background='cyan') but this also didn't work.

Running pyton 3.7 (if this helps)

Where should it be if where it is currently is not correct?

Do you want this? The following code changes background of the canvas-screen

import tkinter as tk
root = tk.Tk()
screen = tk.Canvas(root, bg="cyan") # <--- bg="cyan"
screen.grid()
root.mainloop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM