mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
fixed geometry string scaling
This commit is contained in:
parent
60b13bf215
commit
940ed128bd
@ -3,6 +3,7 @@ __version__ = "4.1.0"
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from tkinter.constants import *
|
from tkinter.constants import *
|
||||||
|
from tkinter import StringVar, IntVar, DoubleVar, BooleanVar
|
||||||
|
|
||||||
# import manager classes
|
# import manager classes
|
||||||
from .settings import Settings
|
from .settings import Settings
|
||||||
|
@ -138,18 +138,7 @@ class CTk(tkinter.Tk):
|
|||||||
self.current_height = max(self.min_height, min(numbers[1], self.max_height))
|
self.current_height = max(self.min_height, min(numbers[1], self.max_height))
|
||||||
|
|
||||||
def apply_geometry_scaling(self, geometry_string):
|
def apply_geometry_scaling(self, geometry_string):
|
||||||
numbers = list(map(int, re.split(r"[x+]", geometry_string))) # split geometry string into list of numbers
|
return re.sub(re.compile("\d+"), lambda match_obj: str(round(int(match_obj.group(0)) * self.window_scaling)), geometry_string)
|
||||||
|
|
||||||
if len(numbers) == 2:
|
|
||||||
return f"{self.apply_window_scaling(numbers[0]):.0f}x" +\
|
|
||||||
f"{self.apply_window_scaling(numbers[1]):.0f}"
|
|
||||||
elif len(numbers) == 4:
|
|
||||||
return f"{self.apply_window_scaling(numbers[0]):.0f}x" +\
|
|
||||||
f"{self.apply_window_scaling(numbers[1]):.0f}+" +\
|
|
||||||
f"{self.apply_window_scaling(numbers[2]):.0f}+" +\
|
|
||||||
f"{self.apply_window_scaling(numbers[3]):.0f}"
|
|
||||||
else:
|
|
||||||
return geometry_string
|
|
||||||
|
|
||||||
def apply_window_scaling(self, value):
|
def apply_window_scaling(self, value):
|
||||||
if isinstance(value, (int, float)):
|
if isinstance(value, (int, float)):
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
from tkinter import *
|
import tkinter
|
||||||
import customtkinter
|
import customtkinter
|
||||||
|
|
||||||
ws = customtkinter.CTk()
|
app = customtkinter.CTk()
|
||||||
ws.title('PythonGuides')
|
app.title('test_optionmenu.py')
|
||||||
ws.geometry('400x300')
|
app.geometry('400x300')
|
||||||
|
|
||||||
def display_selected(choice):
|
|
||||||
|
def select_callback(choice):
|
||||||
choice = variable.get()
|
choice = variable.get()
|
||||||
print("display_selected", choice)
|
print("display_selected", choice)
|
||||||
|
|
||||||
countries = ['Bahamas','Canada', 'Cuba','United States']
|
|
||||||
|
|
||||||
# setting variable for Integers
|
countries = ['Bahamas', 'Canada', 'Cuba', 'United States']
|
||||||
variable = StringVar()
|
|
||||||
|
variable = tkinter.StringVar()
|
||||||
variable.set("test")
|
variable.set("test")
|
||||||
|
|
||||||
# creating widget
|
optionmenu_tk = tkinter.OptionMenu(app, variable, *countries, command=select_callback)
|
||||||
optionmenu_tk = OptionMenu(ws, variable, *countries, command=display_selected)
|
|
||||||
optionmenu_tk.pack(pady=10, padx=10)
|
optionmenu_tk.pack(pady=10, padx=10)
|
||||||
|
|
||||||
optionmenu_1 = customtkinter.CTkOptionMenu(master=ws, variable=variable, values=countries, command=display_selected)
|
optionmenu_1 = customtkinter.CTkOptionMenu(app, variable=variable, values=countries, command=select_callback)
|
||||||
optionmenu_1.pack(pady=10, padx=10)
|
optionmenu_1.pack(pady=10, padx=10)
|
||||||
|
optionmenu_1.set("te")
|
||||||
|
|
||||||
# infinite loop
|
app.mainloop()
|
||||||
ws.mainloop()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user