日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python tkinter pack 同一行_用python tkinter中的一行连接2个复选按钮

發布時間:2023/12/10 python 63 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python tkinter pack 同一行_用python tkinter中的一行连接2个复选按钮 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我有一個程序在畫布中放置復選按鈕,當選項(另一個復選按鈕)被選中時。我有另一個選項(另一個復選按鈕)來畫線。為了畫線,首先我應該選擇checkbutton“draw a line”,然后單擊放置在畫布中的任何checkbutton,另一個單擊畫布上的任何地方。這個工作與我放置的第一個復選按鈕,但如果我放置了幾個復選按鈕,它只從畫布中的最后一個復選按鈕的地方畫線,而不從我選擇的檢查點畫線。我相信我應該創建一個字典來記錄我放置的復選按鈕,這樣我就可以回調它們了,但是我不知道如何實現它,有什么想法嗎?from tkinter import *

root = Tk()

top_canvas = Canvas(root,width=1376,height=768, bg='light blue')

top_canvas.pack()

buttons = []

class CMD: #Auxilliary function for callbacks using parameters. Syntax: CMD(function, argument1, argument2, ...)

def __init__(s1, func, *args):

s1.func = func

s1.args = args

def __call__(s1, *args):

args = s1.args+args

s1.func(*args)

def color_checkbutton(pos): # define the colors of the checkbutton

checkbutton_available()

if buttons[pos][0].get() == 1:

buttons[pos][2].configure(bg='red')

else:

buttons[pos][2].configure(bg='green')

def place_checkbutton_in_canvas(e): # order to insert the checkbutton

if len(str(e.widget))<12: ## Don't place a new one if a checkbox was clicked

b = IntVar()

pos = len(buttons)

global xx, yy

xx = e.x

yy = e.y

buttons.append([b,pos, Checkbutton(top_canvas, variable=b, textvariable=b, command=CMD(color_checkbutton, pos))])

buttons[-1][2].place(x=xx, y=yy)

color_checkbutton(pos)

def place_checkbutton(): #to run when checkbutton is selected. Now the checkbutton will be placed where mouse clicked if choose_line is selected

top_canvas.bind('', place_checkbutton_in_canvas)

def checkbutton_available():

def drawline(ev):

flx = ev.x

fly = ev.y

def auxiliary():

lineor = top_canvas.create_line(xx, yy, flx, fly, width =3, fill = 'red')

auxiliary()

if chosen_option.get() == 2:

top_canvas.bind('', drawline)

chosen_option = IntVar()

choose_checkbutton = Radiobutton(top_canvas, text = "place checkbutton", variable=chosen_option, value = 1, command = place_checkbutton)

choose_checkbutton.place(x=10, y=10)

choose_line = Radiobutton(top_canvas, text = "draw line", variable=chosen_option, value = 2)

choose_line.place(x=10, y=100)

top_canvas.bind('', place_checkbutton_in_canvas)

root.mainloop()

總結

以上是生活随笔為你收集整理的python tkinter pack 同一行_用python tkinter中的一行连接2个复选按钮的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。