精华内容
下载资源
问答
  • 我正在编写绘图程序,我正在尝试更改画布背景颜色,但由于某种原因它不起作用 . 没有错误消息,我不知道为什么它不起作用,因为我使用几乎相同的代码来更改线条颜色 .附:我是python的新手 .码:from tkinter import...

    我正在编写绘图程序,我正在尝试更改画布背景颜色,但由于某种原因它不起作用 . 没有错误消息,我不知道为什么它不起作用,因为我使用几乎相同的代码来更改线条颜色 .

    附:我是python的新手 .

    码:

    from tkinter import *

    # canvas specifications/variables

    canvas_height = 400

    canvas_width = 600

    p1_canvas_colour = "white"

    p1_canvas_colour_number = 1

    #p1 (what you draw with) specifications/variables

    p1_x = canvas_width/2

    p1_y = canvas_height

    p1_colour = "black"

    p1_colour_change = 1

    line_width = 1

    line_length = 1

    #p1 controls

    def p1_move_N(event):

    global p1_y

    canvas.create_line(p1_x, p1_y, p1_x, (p1_y-line_length), width=line_width, fill=p1_colour)

    p1_y = p1_y - line_length

    def p1_move_S(event):

    global p1_y

    canvas.create_line(p1_x, p1_y, p1_x, (p1_y+line_length), width=line_width, fill=p1_colour)

    p1_y = p1_y + line_length

    def p1_move_E(event):

    global p1_x

    canvas.create_line(p1_x, p1_y, (p1_x+line_length), p1_y, width=line_width, fill=p1_colour)

    p1_x = p1_x + line_length

    def p1_move_W(event):

    global p1_x

    canvas.create_line(p1_x, p1_y, (p1_x-line_length), p1_y, width=line_width, fill=p1_colour)

    p1_x = p1_x - line_length

    def erase_all(event):

    canvas.delete(ALL)

    #the p1 colour change

    def p1_line_colour_change(event):

    global p1_colour

    global p1_colour_change

    p1_colour_change += 1

    if p1_colour_change == 1:

    p1_colour = ("black")

    if p1_colour_change == 2:

    p1_colour = ("white")

    if p1_colour_change == 3:

    p1_colour = ("red")

    if p1_colour_change == 4:

    p1_colour = ("orange")

    if p1_colour_change == 5:

    p1_colour = ("yellow")

    if p1_colour_change == 6:

    p1_colour = ("green")

    if p1_colour_change == 7:

    p1_colour = ("blue")

    if p1_colour_change == 8:

    p1_colour = ("purple")

    if p1_colour_change == 9:

    p1_colour = ("pink")

    if p1_colour_change == 10:

    p1_colour = ("brown")

    if p1_colour_change == 11:

    p1_colour_change = 1

    p1_colour = ("black")

    #the canvas colour change

    def p1_canvas_colour_change(event):

    global p1_canvas_colour

    global p1_canvas_colour_number

    p1_canvas_colour_number += 1

    if p1_canvas_colour_number == 1:

    p1_canvas_colour = ("white")

    if p1_canvas_colour_number == 2:

    p1_canvas_colour = ("black")

    if p1_canvas_colour_number == 3:

    p1_canvas_colour = ("red")

    if p1_canvas_colour_number == 4:

    p1_canvas_colour = ("orange")

    if p1_canvas_colour_number == 5:

    p1_canvas_colour = ("yellow")

    if p1_canvas_colour_number == 6:

    p1_canvas_colour = ("green")

    if p1_canvas_colour_number == 7:

    p1_canvas_colour = ("blue")

    if p1_canvas_colour_number == 8:

    p1_canvas_colour = ("purple")

    if p1_canvas_colour_number == 9:

    p1_canvas_colour = ("pink")

    if p1_canvas_colour_number == 10:

    p1_canvas_colour = ("brown")

    if p1_canvas_colour_number == 11:

    p1_canvas_colour_number = 1

    p1_canvas_colour = ("white")

    #the window/canvas

    window = Tk()

    window.title("Drawing")

    canvas = Canvas(bg=p1_canvas_colour, height=canvas_height, width=canvas_width, highlightthickness=0)

    canvas.pack()

    #binding the functions to keys

    window.bind("", p1_move_N)

    window.bind("", p1_move_S)

    window.bind("", p1_move_W)

    window.bind("", p1_move_E)

    window.bind("", erase_all)

    window.bind("", p1_line_colour_change)

    window.bind("", p1_canvas_colour_change)

    window.mainloop()

    展开全文
  • 我正在编写一个绘图程序,我试图做出一个选择,改变画布背景颜色,但由于某些原因,它不起作用。没有错误信息,我不知道为什么它不起作用,因为我用了几乎相同的代码来改变线的颜色。在另外,我对python很陌生。在...

    我正在编写一个绘图程序,我试图做出一个选择,改变画布背景颜色,但由于某些原因,它不起作用。没有错误信息,我不知道为什么它不起作用,因为我用了几乎相同的代码来改变线的颜色。在

    另外,我对python很陌生。在

    代码:from tkinter import *

    # canvas specifications/variables

    canvas_height = 400

    canvas_width = 600

    p1_canvas_colour = "white"

    p1_canvas_colour_number = 1

    #p1 (what you draw with) specifications/variables

    p1_x = canvas_width/2

    p1_y = canvas_height

    p1_colour = "black"

    p1_colour_change = 1

    line_width = 1

    line_length = 1

    #p1 controls

    def p1_move_N(event):

    global p1_y

    canvas.create_line(p1_x, p1_y, p1_x, (p1_y-line_length), width=line_width, fill=p1_colour)

    p1_y = p1_y - line_length

    def p1_move_S(event):

    global p1_y

    canvas.create_line(p1_x, p1_y, p1_x, (p1_y+line_length), width=line_width, fill=p1_colour)

    p1_y = p1_y + line_length

    def p1_move_E(event):

    global p1_x

    canvas.create_line(p1_x, p1_y, (p1_x+line_length), p1_y, width=line_width, fill=p1_colour)

    p1_x = p1_x + line_length

    def p1_move_W(event):

    global p1_x

    canvas.create_line(p1_x, p1_y, (p1_x-line_length), p1_y, width=line_width, fill=p1_colour)

    p1_x = p1_x - line_length

    def erase_all(event):

    canvas.delete(ALL)

    #the p1 colour change

    def p1_line_colour_change(event):

    global p1_colour

    global p1_colour_change

    p1_colour_change += 1

    if p1_colour_change == 1:

    p1_colour = ("black")

    if p1_colour_change == 2:

    p1_colour = ("white")

    if p1_colour_change == 3:

    p1_colour = ("red")

    if p1_colour_change == 4:

    p1_colour = ("orange")

    if p1_colour_change == 5:

    p1_colour = ("yellow")

    if p1_colour_change == 6:

    p1_colour = ("green")

    if p1_colour_change == 7:

    p1_colour = ("blue")

    if p1_colour_change == 8:

    p1_colour = ("purple")

    if p1_colour_change == 9:

    p1_colour = ("pink")

    if p1_colour_change == 10:

    p1_colour = ("brown")

    if p1_colour_change == 11:

    p1_colour_change = 1

    p1_colour = ("black")

    #the canvas colour change

    def p1_canvas_colour_change(event):

    global p1_canvas_colour

    global p1_canvas_colour_number

    p1_canvas_colour_number += 1

    if p1_canvas_colour_number == 1:

    p1_canvas_colour = ("white")

    if p1_canvas_colour_number == 2:

    p1_canvas_colour = ("black")

    if p1_canvas_colour_number == 3:

    p1_canvas_colour = ("red")

    if p1_canvas_colour_number == 4:

    p1_canvas_colour = ("orange")

    if p1_canvas_colour_number == 5:

    p1_canvas_colour = ("yellow")

    if p1_canvas_colour_number == 6:

    p1_canvas_colour = ("green")

    if p1_canvas_colour_number == 7:

    p1_canvas_colour = ("blue")

    if p1_canvas_colour_number == 8:

    p1_canvas_colour = ("purple")

    if p1_canvas_colour_number == 9:

    p1_canvas_colour = ("pink")

    if p1_canvas_colour_number == 10:

    p1_canvas_colour = ("brown")

    if p1_canvas_colour_number == 11:

    p1_canvas_colour_number = 1

    p1_canvas_colour = ("white")

    #the window/canvas

    window = Tk()

    window.title("Drawing")

    canvas = Canvas(bg=p1_canvas_colour, height=canvas_height, width=canvas_width, highlightthickness=0)

    canvas.pack()

    #binding the functions to keys

    window.bind("", p1_move_N)

    window.bind("", p1_move_S)

    window.bind("", p1_move_W)

    window.bind("", p1_move_E)

    window.bind("", erase_all)

    window.bind("", p1_line_colour_change)

    window.bind("", p1_canvas_colour_change)

    window.mainloop()

    展开全文
  • Code: from tkinter import * # canvas specifications/variables canvas_height = 400 canvas_width = 600 p1_canvas_colour = "white" p1_canvas_colour_number = 1 #p1 (what you draw with) specifications/...

    I am coding a drawing program and I am trying to make an option to change the canvas background colour but for some reason it doesn't work. There is no error message and I have no idea why it doesn't work as I used pretty much the same code for changing the line colour.

    P.S. I am very new to python.

    Code:

    from tkinter import *

    # canvas specifications/variables

    canvas_height = 400

    canvas_width = 600

    p1_canvas_colour = "white"

    p1_canvas_colour_number = 1

    #p1 (what you draw with) specifications/variables

    p1_x = canvas_width/2

    p1_y = canvas_height

    p1_colour = "black"

    p1_colour_change = 1

    line_width = 1

    line_length = 1

    #p1 controls

    def p1_move_N(event):

    global p1_y

    canvas.create_line(p1_x, p1_y, p1_x, (p1_y-line_length), width=line_width, fill=p1_colour)

    p1_y = p1_y - line_length

    def p1_move_S(event):

    global p1_y

    canvas.create_line(p1_x, p1_y, p1_x, (p1_y+line_length), width=line_width, fill=p1_colour)

    p1_y = p1_y + line_length

    def p1_move_E(event):

    global p1_x

    canvas.create_line(p1_x, p1_y, (p1_x+line_length), p1_y, width=line_width, fill=p1_colour)

    p1_x = p1_x + line_length

    def p1_move_W(event):

    global p1_x

    canvas.create_line(p1_x, p1_y, (p1_x-line_length), p1_y, width=line_width, fill=p1_colour)

    p1_x = p1_x - line_length

    def erase_all(event):

    canvas.delete(ALL)

    #the p1 colour change

    def p1_line_colour_change(event):

    global p1_colour

    global p1_colour_change

    p1_colour_change += 1

    if p1_colour_change == 1:

    p1_colour = ("black")

    if p1_colour_change == 2:

    p1_colour = ("white")

    if p1_colour_change == 3:

    p1_colour = ("red")

    if p1_colour_change == 4:

    p1_colour = ("orange")

    if p1_colour_change == 5:

    p1_colour = ("yellow")

    if p1_colour_change == 6:

    p1_colour = ("green")

    if p1_colour_change == 7:

    p1_colour = ("blue")

    if p1_colour_change == 8:

    p1_colour = ("purple")

    if p1_colour_change == 9:

    p1_colour = ("pink")

    if p1_colour_change == 10:

    p1_colour = ("brown")

    if p1_colour_change == 11:

    p1_colour_change = 1

    p1_colour = ("black")

    #the canvas colour change

    def p1_canvas_colour_change(event):

    global p1_canvas_colour

    global p1_canvas_colour_number

    p1_canvas_colour_number += 1

    if p1_canvas_colour_number == 1:

    p1_canvas_colour = ("white")

    if p1_canvas_colour_number == 2:

    p1_canvas_colour = ("black")

    if p1_canvas_colour_number == 3:

    p1_canvas_colour = ("red")

    if p1_canvas_colour_number == 4:

    p1_canvas_colour = ("orange")

    if p1_canvas_colour_number == 5:

    p1_canvas_colour = ("yellow")

    if p1_canvas_colour_number == 6:

    p1_canvas_colour = ("green")

    if p1_canvas_colour_number == 7:

    p1_canvas_colour = ("blue")

    if p1_canvas_colour_number == 8:

    p1_canvas_colour = ("purple")

    if p1_canvas_colour_number == 9:

    p1_canvas_colour = ("pink")

    if p1_canvas_colour_number == 10:

    p1_canvas_colour = ("brown")

    if p1_canvas_colour_number == 11:

    p1_canvas_colour_number = 1

    p1_canvas_colour = ("white")

    #the window/canvas

    window = Tk()

    window.title("Drawing")

    canvas = Canvas(bg=p1_canvas_colour, height=canvas_height, width=canvas_width, highlightthickness=0)

    canvas.pack()

    #binding the functions to keys

    window.bind("", p1_move_N)

    window.bind("", p1_move_S)

    window.bind("", p1_move_W)

    window.bind("", p1_move_E)

    window.bind("", erase_all)

    window.bind("", p1_line_colour_change)

    window.bind("", p1_canvas_colour_change)

    window.mainloop()

    解决方案

    you need to reconfigure your canvas in order to apply the change,

    add the following line at the end of your "p1_canvas_colour_change" method:

    canvas.configure(background=p1_canvas_colour)

    展开全文
  • 调整label背景颜色测试截图我们都知道,一般来说每个像素的数据包括rgb三个通道用三个字节来表示如0xff9900 中 ff是红色的量 99是绿色的量 00是蓝色的量代码实现了用 scale滑动条来调节 rgb的占比,从而调节颜色源码...

    调整label背景颜色测试截图

    我们都知道,一般来说每个像素的数据包括rgb三个通道用三个字节来表示

    如0xff9900 中 ff是红色的量 99是绿色的量 00是蓝色的量

    代码实现了用 scale滑动条来调节 rgb的占比,从而调节颜色

    源码

    import tkinter as tk

    window = tk.Tk() # 实例化一个窗口

    window.title('Color setting') # 定义窗口标题

    window.geometry('400x600') # 定义窗口大小

    l = tk.Label(window, bg='yellow', width=200, height=2, text='empty')

    l.pack()

    r,g,b,w=100,100,100,100

    def print_selection():

    global r,g,b,w

    #转化16进制并格式化

    rv =hex(int(255.0*(float(r)*float(w)/10000.0)))#0x xx 不合适

    srv='%02x'%int(255.0*(float(r)*float(w)/10000.0))

    sgv = '%02x' % int(255.0 * (float(g) * float(w) / 10000.0))

    sbv = '%02x' % int(255.0 * (float(b) * float(w) / 10000.0))

    #print(srv)

    bgstr="#"+srv+sgv+sbv

    l.configure(bg=bgstr)

    l.config(text='R:' + str(r) + '%,G:' + str(g) + '%,B:' + str(b) + '%,W:' + str(w)+"% C:"+bgstr)

    jsonstr="\"color\":{\"r\":%1.2f,\"g\":%1.2f,\"b\":%1.2f,\"w\":%1.2f}"%(float(r)/100.0,float(g)/100.0,float(b)/100.0,float(w)/100.0)

    fresh(jsonstr)

    def setR(v):

    global r

    r=v

    print_selection()

    def setG(v):

    global g

    g=v

    print_selection()

    def setB(v):

    global b

    b=v

    print_selection()

    def setW(v):

    global w

    w=v

    print_selection()

    rs = tk.Scale(window, label='R:', from_=0, to=100, orient=tk.HORIZONTAL, length=200, showvalue=1, tickinterval=25,

    resolution=1, command=setR)

    rs.pack() # 显示名字 从5-11 条方向 长度(像素),是否直接显示值,标签的单位长度,保留精度 ,定义功能

    rs.set(r)

    gs = tk.Scale(window, label='G:', from_=0, to=100, orient=tk.HORIZONTAL, length=200, showvalue=1, tickinterval=25,

    resolution=1, command=setG)

    gs.pack()

    gs.set(g)

    bs = tk.Scale(window, label='B:', from_=0, to=100, orient=tk.HORIZONTAL, length=200, showvalue=1, tickinterval=25,

    resolution=1, command=setB)

    bs.pack()

    bs.set(b)

    ws = tk.Scale(window, label='W:', from_=0, to=100, orient=tk.HORIZONTAL, length=200, showvalue=1, tickinterval=25,

    resolution=1, command=setW)

    ws.pack()

    ws.set(w)

    text1 = tk.Text(window,width=30,height=5)

    text1.pack()

    text1.insert(tk.INSERT,'I love you')

    def fresh(t):

    text1.delete(1.0, tk.END)

    text1.insert(tk.INSERT, t)

    def show():

    T1 = text1.get(0.0, tk.END)

    print(T1)

    def cut(event=None):

    text1.event_generate("<>")

    def copy(event=None):

    text1.get('sel.first', 'sel.last')

    text1.event_generate("<>")

    def paste(event=None):

    text1.event_generate('<>')

    # Select all the text in textbox

    def select_all(event=None):

    text1.tag_add(tk.SEL, "1.0", tk.END)

    text1.mark_set(tk.INSERT, "1.0")

    text1.see(tk.INSERT)

    copy()

    return 'break'

    button = tk.Button(window,text="SelectAndCopy",command=select_all)

    button.pack()

    text1.focus_set()

    #button.pack(fill=tk.BOTH, expand=1)

    #text1.window_create(tk.INSERT,window=button)

    window.mainloop()

    展开全文
  • python tkinter调整label背景颜色的测试

    万次阅读 2019-02-08 23:11:14
    调整label背景颜色测试截图 我们都知道,一般来说每个像素的数据包括rgb三个通道用三个字节来表示 如0xff9900 中 ff是红色的量 99是绿色的量 00是蓝色的量 代码实现了用 scale滑动条来调节 rgb的占比,从而调节...
  • 我试图在窗口小部件没有焦点时更改Mac OS X上Tkinter文本窗口小部件中所选文本的默认背景颜色.默认的未聚焦选择颜色为灰色.经过几个小时的搜索,我无法找到一个开箱即用的解决方案来做到这一点.这是我尝试过的:>...
  • 2.标签控件——Label在tkinter中,可以显示文本和图像的控件有很多,但能够二者兼顾的一个最简单的控件,就是标签(Label)。如果你需要显示一行或多行文本...l = Label(root) #如果只有一个窗口,root也可以省略 l...
  • Python爬虫、数据分析、网站开发等案例教程视频免费在线观看 ... 添加标题 # 设置窗口标题 root.title("title") ...# 设置背景色,可以用英文名,也可以用十六进制表示的颜色。 root["background
  • 我想制作一个不同颜色方块的大网格,所以我使用背景颜色设置的标签来制作正方形 . 我想在用户展开窗口时自动调整方块的大小,然后让它们调整大小并缩小到与窗口大小减小相同的大小 .像这样的东西:这样调整大小和...
  • 我想制作一个不同颜色方块的大网格,所以我使用背景颜色设置的标签来制作正方形.我想在用户展开窗口时自动调整方块大小,然后让它们调整大小并缩小到与窗口大小减小相同的大小.像这样的东西:这样调整大小和均匀缩放:...
  • 要求使用tkinter生成如下窗口:图片.png图片.png在右上角文本框输入名字,在旁边的下拉框选择数字,点击"Click Me!", "Click Me!"的文本将改变成如下:图片.png可以选择"Unchecked"和"Enabled"的其中一个。点击Blue...
  • 在我的Mac上使用基于Tkinter ttk的GUI时,我注意到背景颜色和Notebook小部件存在问题.将ttk.Frame添加为ttk.Notebook选项卡时,框架的显示背景与笔记本选项卡的“插入”背景不匹配.如何使ttk.Frame与周围的背景颜色相...
  • 要求使用tkinter生成如下窗口: 图片.png 图片.png在右上角文本框输入名字,在旁边的下拉框选择数字,点击"Click Me!", "Click Me!"的文本将改变成如下: 图片.png可以选择"Unchecked"和"Enabled"的其中一个。点击...
  • 我想制作一个不同颜色方块的大网格,所以我使用背景颜色设置的标签来制作正方形.我想在用户展开窗口时自动调整方块大小,然后让它们调整大小并缩小到与窗口大小减小相同的大小.像这样的东西:这样调整大小和均匀缩放:...
  • 做GUI程序,除了设置组件的各种属性外,有时还需要获取组件的属性值。...我们来看看Win系统和Ubuntu桌面系统下,默认的root窗口背景颜色:Win系统:>>> import tkinter as tk>>> root = tk.Tk()...
  • 要求使用tkinter生成如下窗口:在右上角文本框输入名字,在旁边的下拉框选择数字,点击"Click Me!", "Click Me!"的文本将改变成如下:可以选择"Unchecked"和"Enabled"的其中一个。点击Blue、Gold、Red其中的一个,将...
  • 本小节展示的是python tkinter Checkbutton控件 选择了那些Ckeckbutton控件选项则在label控件...window["background"]="#152950"#窗口背景颜色 window.geometry("200x200+30+30")#窗口大小以及距离屏幕桌上角的坐标 #
  • 窗口主体框架from Tkinter import *root = Tk()root.geometry('500x400') #窗口尺寸root.title('自定义标题') #窗口标题#之后补充窗口内容root.mainloop() #让窗口活起来控件标签(Label)...'green', #背景颜色fo...
  • tkinter 编程

    2019-09-18 08:49:47
    1、窗口:能改变标题,大小,背景颜色窗口图标,窗口位置 2、Widget【控件】:窗口的下一级,所有的Widget都是类,通过调用构造方法建立1)每个类都包括建立,关闭,循环,事件绑定和解除2)Widget的共同属性:...
  • Python Tkinter滚动条滚动条小部件用于向下滚动其他小部件的内容,如列表框,文本和画布。...SN选项说明1 activebackground具有焦点时窗口小部件的背景颜色。2 bg小部件的背景颜色。3 bd小部件的...
  • python tkinter place布局

    2021-03-25 06:24:22
    place布局允许通过place方法的参数指定控件的位置(x,y)和尺寸(width,height) Label().place(x=10,y=10,width=100,height=20) 第一个固定背景颜色 ...window['background']='Yellow'#窗口背景颜色 wi
  • 概述 tkinter之旅(第一部分)主要介绍组件及相关内容: Toplevel和Tk组件 Message和Entry组件 Checkbutton、Rodiobutton和Scale组件 ...颜色:bg选项设置背景颜色;fg设置显示文本颜色,支持英文(如:"blue")或
  • 3.27 今日学习Tkinter

    2019-03-28 11:35:00
    在CSDN等上面搜索了一些Tkinter的简易教程,这个库的组件我觉得用起来还是挺方便的,对于窗口,文本框,按钮,背景颜色的设定都很简明,就是单色块的背景颜色看着很辣眼睛。。 ...
  • Tkinter之Button&Label

    2020-12-22 10:11:07
    Tkinter之Button&Label import tkinter as tk ...#创建一个label,在window上面,设置背景颜色,字体和大小,label的宽15,高2字符,字符串变量显示使用textvariable控制,静态的用text就行 l = tk.Label(window,textva
  • 导入tkinter模块 from tkinter import * ...#窗口背景颜色 root.configure(bg = "blue") #让程序持续执行 root.mainloop() 结果图示 标签label 文本标签 Label(root,text='Hello tkinter', fg='white',bg='red',
  • window["background"]="#152950"#窗口背景颜色 window.geometry("300x220+30+30")#窗口大小以及距离屏幕桌上角的坐标 Label(window,bg="pink",width=30,font=("Arial",18),text="幻影坦克").pack(fill.
  • window["background"]="#152950"#窗口背景颜色 window.geometry("300x300+30+30")#窗口的尺寸以及位置 # 控件 参数 Label(window, # window 窗口对象 text="dalaojun", # text 显示文本 fg="#191970", # fg 字体...
  • Python_tkinter_Toplevel

    千次阅读 2018-12-02 22:16:24
    Toplevel 顶层部件的工作,直接由窗口管理器管理的窗口 ... 窗口背景颜色。 borderwidth(bd) 边框宽度(以像素为单位)默认为0。 cursor  当鼠标在此窗口中时出现的光标。 class_  ...
  • 选中的时候背景颜色为红色,点击停止结束 import threading import tkinter import time # 1.实现窗口 root = tkinter.Tk() root.title('美女联盟') root.minsize(300,300) # 2 摆放按钮 btn1 = tkinter.Button...
  • Python Tkinter滚动条滚动条小部件用于向下滚动其他小部件的内容,如列表框,文本和画布。...SN选项说明1 activebackground具有焦点时窗口小部件的背景颜色。2 bg小部件的背景颜色。3 bd小部件的...

空空如也

空空如也

1 2 3
收藏数 41
精华内容 16
关键字:

tkinter窗口背景颜色