它不是來自 tkinter 的滑塊,所以它可以解釋為什么即使在配置或樣式中我也不能使用fg或著色。foreground我檢查了檔案,沒有發現任何關于更改數字顏色的資訊(它沒有出現在屬性中)
https://github.com/harshvinay752/RangeSlider
hVar1 = DoubleVar() #left handle variable
hVar2 = DoubleVar() #right handle variable
rs1 = RangeSliderH(root , [hVar1, hVar2],bar_color_outer='blue' ,bgColor='red',
line_s_color='green', line_color='gray', Width=400, Height=65,padX=17 ,min_val=0, max_val=20,
show_value= True ) #horizontal
我怎么能做到這一點?有什么解決辦法嗎?
uj5u.com熱心網友回復:
您可以創建一個自定義類,RangeSliderH并添加value_color選項來設定覆寫函式內顯示值的顏色getValues():
...
class MyRangeSliderH(RangeSliderH):
def __init__(self, master, variables, **kwargs):
self.value_color = kwargs.pop('value_color', 'black')
super().__init__(master, variables, **kwargs)
# override getValues()
def getValues(self):
if self.show_value:
# update the color of the shown values
for bar in self.bars:
self.canv.itemconfig(bar['Ids'][-1], fill=self.value_color)
return super().getValues()
...
# Use MyRangeSliderH instead with given value_color
rs1 = MyRangeSliderH(root , [hVar1, hVar2],bar_color_outer='blue' ,bgColor='red',
line_s_color='green', line_color='gray', Width=400, Height=65,padX=17 ,min_val=0, max_val=20,
show_value= True, value_color='yellow') #horizontal
...
更新:如果您不想使用類,您可以使用 tkinter 變數跟蹤使用.trace_add()來在值更改時更新顏色:
hVar1 = DoubleVar() #left handle variable
hVar2 = DoubleVar() #right handle variable
rs1 = RangeSliderH(root , [hVar1, hVar2],bar_color_outer='blue' ,bgColor='red',
line_s_color='green', line_color='gray', Width=400, Height=65,padX=17 ,min_val=0, max_val=20,
show_value= True ) #horizontal
def update_value_color(slider, color='yellow'):
if slider.show_value:
for bar in slider.bars:
slider.canv.itemconfig(bar['Ids'][-1], fill=color)
hVar1.trace_add('write', lambda *_: update_value_color(rs1))
update_value_color(rs1) # update the value color initially
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/505396.html
上一篇:更新發送的訊息數量
下一篇:從訊息框Tkinter呼叫函式
