added readonly state to CTkComboBox

This commit is contained in:
Tom Schimansky 2022-07-07 18:19:23 +02:00
parent de33629e7d
commit c95c0b7050
2 changed files with 13 additions and 10 deletions

View File

@ -1,9 +1,7 @@
import tkinter import tkinter
import sys import sys
from typing import Union
from .dropdown_menu import DropdownMenu from .dropdown_menu import DropdownMenu
from .ctk_canvas import CTkCanvas from .ctk_canvas import CTkCanvas
from ..theme_manager import ThemeManager from ..theme_manager import ThemeManager
from ..settings import Settings from ..settings import Settings
@ -56,7 +54,7 @@ class CTkComboBox(CTkBaseClass):
# callback and hover functionality # callback and hover functionality
self.command = command self.command = command
self.variable = variable self.textvariable = variable
self.state = state self.state = state
self.hover = hover self.hover = hover
@ -114,8 +112,8 @@ class CTkComboBox(CTkBaseClass):
self.canvas.tag_bind("dropdown_arrow", "<Button-1>", self.clicked) self.canvas.tag_bind("dropdown_arrow", "<Button-1>", self.clicked)
self.bind('<Configure>', self.update_dimensions_event) self.bind('<Configure>', self.update_dimensions_event)
if self.variable is not None: if self.textvariable is not None:
self.entry.configure(textvariable=self.variable) self.entry.configure(textvariable=self.textvariable)
def set_scaling(self, *args, **kwargs): def set_scaling(self, *args, **kwargs):
super().set_scaling(*args, **kwargs) super().set_scaling(*args, **kwargs)
@ -209,8 +207,8 @@ class CTkComboBox(CTkBaseClass):
self.command = kwargs.pop("command") self.command = kwargs.pop("command")
if "variable" in kwargs: if "variable" in kwargs:
self.variable = kwargs.pop("variable") self.textvariable = kwargs.pop("variable")
self.entry.configure(textvariable=self.variable) self.entry.configure(textvariable=self.textvariable)
if "width" in kwargs: if "width" in kwargs:
self.set_dimensions(width=kwargs.pop("width")) self.set_dimensions(width=kwargs.pop("width"))
@ -269,8 +267,14 @@ class CTkComboBox(CTkBaseClass):
def set(self, value: str, from_variable_callback: bool = False): def set(self, value: str, from_variable_callback: bool = False):
self.current_value = value self.current_value = value
self.entry.delete(0, tkinter.END) if self.state == "readonly":
self.entry.insert(0, self.current_value) self.entry.configure(state="normal")
self.entry.delete(0, tkinter.END)
self.entry.insert(0, self.current_value)
self.entry.configure(state="readonly")
else:
self.entry.delete(0, tkinter.END)
self.entry.insert(0, self.current_value)
if not from_variable_callback: if not from_variable_callback:
if self.command is not None: if self.command is not None:

View File

@ -226,7 +226,6 @@ class CTkEntry(CTkBaseClass):
self.entry.delete(*args, **kwargs) self.entry.delete(*args, **kwargs)
if self.entry.get() == "": if self.entry.get() == "":
self.placeholder_text_active = True
self.set_placeholder() self.set_placeholder()
def insert(self, *args, **kwargs): def insert(self, *args, **kwargs):