Форум сайта python.su
Помогите пожалуйста!кто подскажет как менять цвет внутри фигуры (треугольник) кнопками Radiobutton
var = IntVar()
var.set(0)
col1 = Radiobutton( text=“Светло-голубой”, variable=var, value=0 , command=change)
col2 = Radiobutton( text=“Зеленый”, variable=var, value=1,command=change)
Отредактировано ydadonov (Май 19, 2020 12:49:36)
Офлайн
вот образец
Офлайн
вот
Прикреплённый файлы: цвет.PNG (22,3 KБ)
Офлайн
https://younglinux.info/tkinter/variable.php
практически оин в один задача.
[code python][/code]
Отредактировано PEHDOM (Май 19, 2020 12:52:45)
Офлайн
Как менять переменную цвета? весь инет перевернул нет образцов
Офлайн
elif var.get() == 2:
canvas.create_polygon(,,,outline='#000000',fill='#8b00ff')
elif var.get() == 3:
canvas.create_polygon(,,,outline='#000000',fill='#800080')
elif var.get() == 4:
canvas.create_polygon(,,,outline='#000000',fill='#cc7722')
elif var.get() == 5:
canvas.create_polygon(,,,outline='#000000',fill='#db7093')
print(colors)
#colors='#87cefa'
canvas.create_polygon(,,,outline='#000000',fill=colors)
#выбор цвета для треугольника с помощью радиокнопок
var = IntVar()
var.set(0)
col1 = Radiobutton( text=“Светло-голубой”, variable=var, value=0 , command=change)
col2 = Radiobutton( text=“Зеленый”, variable=var, value=1,command=change)
col3 = Radiobutton(text=“Фиолетовый”, variable=var, value=2,command=change)
col4 = Radiobutton(text=“Пурпурный”, variable=var, value=3,command=change)
col5 = Radiobutton(text=“Охра”, variable=var, value=4,command=change)
col6 = Radiobutton(text=“Лиловый”, variable=var, value=5,command=change)
col1.place(x=500, y=50)
col2.place(x=500, y=70)
col3.place(x=500, y=90)
col4.place(x=500, y=110)
col5.place(x=500, y=130)
col6.place(x=500, y=150)
Офлайн
получается толь если все целиком писать а переменную цвета как сменить не знаю
Офлайн
как нет ? https://www.tutorialspoint.com/python/tk_colors.htm
http://www.science.smith.edu/dftwiki/index.php/Color_Charts_for_TKinter
[code python][/code]
Офлайн
ydadonovчто вы называете “переменной цвета”?
а переменную цвета как сменить не знаю
[code python][/code]
Офлайн
from tkinter import * # Измененние заголовка окна формы def b1(event): if root.title() == 'Дадонов Юрий Петрович': root.title('ID=704456768') else: root.title('Дадонов Юрий Петрович') root = Tk() root.title('Дадонов Юрий Петрович') root.bind('<Button-1>', b1) # рисование системы координат с подписями canvas = Canvas(root,width=800,height=600,bg="#ffffff") canvas.pack() canvas.create_line(20,310,20,10,width=5,fill="red",arrow=LAST) canvas.create_line(10,300,500,300,width=5,fill="red",arrow=LAST) canvas.create_text(10, 320, anchor=W, font="Purisa", fill="red", text="0") canvas.create_text(10, 10, anchor=W, font="Purisa",fill="red", text="y") canvas.create_text(500, 310, anchor=W, font="Purisa",fill="red", text="x") # получение координат для рисования треугольника ID=704456768 x1=ID % 1000000//10000 +20 x2=ID % 1000000%10000//100 +20 x3=ID % 1000000%100 +20 ID3=ID//3 y1=300 - ID3 % 1000000//10000 y2=300 - ID3 % 1000000%10000//100 y3=300 - ID3 % 1000000%100 #рисование треугольника по заданным координатам colors='#87cefa' def change(): if var.get() == 0: canvas.create_polygon([x1,y1],[x2,y2],[x3,y3],outline='#000000',fill='#87cefa') elif var.get() == 1: colors='green' print(colors) elif var.get() == 2: canvas.create_polygon([x1,y1],[x2,y2],[x3,y3],outline='#000000',fill='#8b00ff') elif var.get() == 3: canvas.create_polygon([x1,y1],[x2,y2],[x3,y3],outline='#000000',fill='#800080') elif var.get() == 4: canvas.create_polygon([x1,y1],[x2,y2],[x3,y3],outline='#000000',fill='#cc7722') elif var.get() == 5: canvas.create_polygon([x1,y1],[x2,y2],[x3,y3],outline='#000000',fill='#db7093') print(colors) #colors='#87cefa' canvas.create_polygon([x1,y1],[x2,y2],[x3,y3],outline='#000000',fill=colors) #выбор цвета для треугольника с помощью радиокнопок var = IntVar() var.set(0) col1 = Radiobutton( text="Светло-голубой", variable=var, value=0 , command=change) col2 = Radiobutton( text="Зеленый", variable=var, value=1,command=change) col3 = Radiobutton(text="Фиолетовый", variable=var, value=2,command=change) col4 = Radiobutton(text="Пурпурный", variable=var, value=3,command=change) col5 = Radiobutton(text="Охра", variable=var, value=4,command=change) col6 = Radiobutton(text="Лиловый", variable=var, value=5,command=change) col1.place(x=500, y=50) col2.place(x=500, y=70) col3.place(x=500, y=90) col4.place(x=500, y=110) col5.place(x=500, y=130) col6.place(x=500, y=150) canvas.create_text(50, 390, anchor=W, font="Purisa", fill="red", text="x1:") canvas.create_text(150, 390, anchor=W, font="Purisa", fill="red", text="x2:") canvas.create_text(250, 390, anchor=W, font="Purisa", fill="red", text="x3:") canvas.create_text(50, 490, anchor=W, font="Purisa", fill="red", text="y1:") canvas.create_text(150, 490, anchor=W, font="Purisa", fill="red", text="y2:") canvas.create_text(250, 490, anchor=W, font="Purisa", fill="red", text="y3:") txt1 = Entry(canvas, width=10) txt2 = Entry(canvas, width=10) txt3 = Entry(canvas, width=10) txt4 = Entry(canvas, width=10) txt5 = Entry(canvas, width=10) txt6 = Entry(canvas, width=10) txt1.place(x=50, y=400) txt2.place(x=150, y=400) txt3.place(x=250, y=400) txt4.place(x=50, y=500) txt5.place(x=150, y=500) txt6.place(x=250, y=500) def koord(): x1=int(txt1.get()) x2=int(txt2.get()) x3=int(txt3.get()) y1=int(txt4.get()) y2=int(txt5.get()) y3=int(txt6.get()) canvas.delete(tr) canvas.create_polygon([x1,y1],[x2,y2],[x3,y3],outline='#000000',fill=colors) btn1 = Button(canvas, text="Построить треугольник", command= koord) btn1.place(x=350, y=500) root.mainloop()
Отредактировано ydadonov (Май 19, 2020 13:23:00)
Офлайн