简体   繁体   English

背景颜色-Tkinter

[英]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. 我尝试在canvas.create.line定义背景,但仍然没有运气。 I also had it defined as root.configure(background='cyan') but this also didn't work. 我也将其定义为root.configure(background='cyan')但这也没有用。

Running pyton 3.7 (if this helps) 运行pyton 3.7(如果有帮助)

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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