如何控制tkinter应用程序的亮度



我只是想知道是否有一种方法可以在不影响桌面亮度的情况下更改tkinter应用程序的亮度。

以下是tkinter中亮度颜色的演示。

tk_set_Palette将影响大多数tkinter小部件。哎呀,在我的代码中发现了一个错误,所以我已经清理了


def find( obj ):
'''return string of keys & values for any tkinter widget that has keys attribute'''
name = f"{type(obj).__name__}:n    "
try:
return name + "n    ".join( [ f"{x} = '{obj.cget(x)}'" for x in obj.keys() ] )
except:
return f"'{obj}' has no keys attribute"
class brightness:
def __init__( self ):
self.master = tkinter.Tk()
self.master.update_idletasks()
self.color = 15790320 # #f0f0f0 = SystemButtonFace
self.var = tkinter.IntVar( self.master, value = self.color )
self.flexx( self.master )
self.label = tkinter.LabelFrame(
self.master, labelanchor = 'n', text = self.master['background'] )
self.label.grid( row=0, column=0, columnspan=2, sticky='nsew' )
self.flexx( self.label, r=None )
self.flexx( self.label, r=None , c=1 )
self.down = tkinter.Button(
self.label, text = 'Color down',
command = self.control_down )
self.down.grid( row = 0, column = 0, sticky = 'nsew' )
self.up = tkinter.Button(
self.label, text = 'Color up',
command = self.control_up)
self.up.grid( row = 0, column = 1, sticky = 'nsew' )
self.scroll = tkinter.Scale(
self.label, orient = 'horizontal',
resolution = 65793, label = 'Brightness Control',
from_ = 0, to = 16777215, variable = self.var,
command = self.control )
self.scroll.grid( row = 1, column=0, columnspan=2, sticky='ew' )
self.master.geometry( '200x200' )
self.master.minsize( 334, 113 )
def flexx( self, o, r = 0, c = 0, rw = 1, cw = 1 ):
'''flexx will control grid manager static|dymanic growth'''
if r != None:
o.rowconfigure( r, weight = rw )
if c != None:
o.columnconfigure( c, weight = cw )
def convert( self ):
col = '#' + ( '000000' + hex( self.color )[2:])[~5:]
self.var.set( self.color )
self.label['text'] = col
self.master.tk_setPalette( col )
def control_up( self ):
self.color += 65793
if self.color > 16777215:
self.color = 15790320
col = self.convert( )
def control_down( self ):
self.color -= 65793
if self.color < 0: # 15790320:
self.color = 16777215
col = self.convert( )
def control( self, n ):
self.color = int( n )
col = self.convert( )
if __name__ == '__main__':
bright = brightness( )
tkinter.mainloop()

最新更新