python tkinter treeview 改变颜色,TKinter样式和Treeview点击问题

在Python tkinter中遇到一个问题,当使用style.theme_create创建自定义主题后,Treeview组件无法被点击。尽管尝试了绑定事件、设置cursor、selection_set和focus_set等方法,但问题依然存在。当移除自定义风格后,点击功能恢复正常。问题出在自定义主题中未正确设置Treeview的选中样式。解决方案是,在新主题中为Treeview设置明确的'selected'样式,例如将选中背景设为红色,未选中设为蓝色。
摘要由CSDN通过智能技术生成

I am struggling with styles in TKinter

My main problem is that you cannot click anything in the treeview.

To test, simply press the "Press To Test" Button

For some reason it looks like, style.theme_create takes over my treeview widget, and no matter what I try, I cannot seem to find a solution around it. I tried activating the cursor, selection_set, focus_set, etc.

If I comment the style I can click, but not with it on.

I am still quite new to python and would appreciate some insight.

I tried the t1.bind('') and tried to find a selected style but can't seem to make it work, the bind on its own doesn't work. I've read the documentation but all i've tried related to the selection seems to fail.

#IMPORT LIBRARIES & MODULES

from tkinter import *

from tkinter import ttk

from tkinter import Tk,Frame

from tkinter.ttk import Notebook

from datetime import datetime,date,time

from PIL import ImageTk,Image

import pyodbc

import os, sys

import ldap

#APPLICATION - Start of Application

newroot = Tk()

#APPLICATION - Configure New Window Parameters

newroot.geometry("1200x600")

newroot.title(' PCT ')

newroot.grid_columnconfigure(0, weight=1)

newroot.grid_rowconfigure(0, weight=1)

#SET CUSTOM APPLICATION COLORS

bglight = '#7d8ea3'

bgmid = '#5a6b7e'

bgdark = '#3d4855'

cwhite = '#ffffff'

cgrey = '#dddddd'

#SET STYLING FOR MENU

style = ttk.Style()

style.theme_create( "fclassic", parent="alt", settings={

"TNotebook": {

"configure": {

"tabmargins": [2, 5, 2, 0],

"background": bgdark,

"foreground": cwhite}},

"TNotebook.Tab": {

"configure": {"padding": [5, 1],

"background": bglight,

"foreground": cwhite,

"font": ("Century Gothic", '14', 'italic')},

"map":

{"background": [("selected", bgmid)],

"expand": [("selected", [1, 1, 1, 0])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值