Tim Zheng
New Coder
How to find the problem:
1. click the translate button (you can see the original GUI)
2. click the settings button
3. click the translate button again
and you can find some parts of stuff of overlapping
(btw, my project isn't finished yet, so don't need to care about other problems, thanks)
code below:
1. click the translate button (you can see the original GUI)
2. click the settings button
3. click the translate button again
and you can find some parts of stuff of overlapping
(btw, my project isn't finished yet, so don't need to care about other problems, thanks)
code below:
Code:
import customtkinter as ctk
import tkinter
import customtkinter
import tkinter as tk
from mdict import MDict
Opendict = customtkinter.CTk()
#Main settings___
Opendict.title("OpenDict")
Opendict.geometry("1000x600")
# 初始外观颜色
appearance_color = "dark"
theme_color = "blue"
Font = "Microsoft YaHei"
customtkinter.set_appearance_mode(str(appearance_color))
customtkinter.set_default_color_theme(str(theme_color))
#_Top bar
# Function to perform search (action when clicking the search button)
def search():
query = search_entry.get() # Get the input from the search entry
print(f"Search Query: {query}") # Print the search query (or handle search logic)
# Create an entry widget (search bar) for input
open_dict_label = ctk.CTkLabel(Opendict, text="OpenDict", font=(str(Font), 14, "bold"))
open_dict_label.pack(side="left", padx=8, pady=4, anchor=tkinter.NW)
search_entry = ctk.CTkEntry(Opendict, width=200, placeholder_text="Search here...")
search_entry.pack(side="left", padx=4, pady=5, anchor=tkinter.NW)
# Create a search button to trigger the search function
search_button = ctk.CTkButton(Opendict, width=20, text="🔍", command=search)
search_button.pack(side="left", padx=5, pady=5, anchor=tkinter.NW)
#__Left --> Right_
#————————————————————————Settings settings————————————————————————————————————
is_settings_button_clicked = False
def settings_button_clicked():
global is_settings_button_clicked, Meaning_Bar_right
is_settings_button_clicked = not is_settings_button_clicked
if is_settings_button_clicked:
Meaning_Bar_right = ctk.CTkFrame(Opendict, width=470, height=540, corner_radius=20)
Meaning_Bar_right.place(x=520, y=40)
setting_label = ctk.CTkLabel(Meaning_Bar_right, text="Settings", font=(str(Font), 16, "bold"), text_color="white", bg_color="transparent")
setting_label.place(x=15, y=10) # 放置在 Meaning_Bar_left 上方
setting_label = ctk.CTkLabel(Meaning_Bar_right, text="Theme Color", font=(str(Font), 15), text_color="white", bg_color="transparent")
setting_label.place(x=15, y=50) # 放置在 Meaning_Bar_left 上方
setting_label = ctk.CTkLabel(Meaning_Bar_right, text="Font Style", font=(str(Font), 15), text_color="white", bg_color="transparent")
setting_label.place(x=15, y=100) # 放置在 Meaning_Bar_left 上方
setting_label = ctk.CTkLabel(Meaning_Bar_right, text="@2024 OpenDict by Tim Zheng", font=(str(Font), 10), text_color="grey", bg_color="transparent")
setting_label.place(x=235, y=532, anchor=tkinter.CENTER) # 放置在 Meaning_Bar_left 上方
#________________________________________
mode_options = ["dark", "light", "system"]
# 创建下拉菜单变量
global mode_variable
mode_variable = ctk.StringVar(value=appearance_color) # 默认选择与appearance_color相同的选项
# 创建下拉菜单
mode_dropdown = ctk.CTkOptionMenu(
Meaning_Bar_right,
variable=mode_variable,
values=mode_options,
command=lambda event: update_appearance_mode(mode_variable.get()),
)
mode_dropdown.place(x=115, y=50)
#________________________________________
font_options = ["Ariel", "Georgia", "Verdana", "Garamond"]
# 创建下拉菜单变量
global font_variable
font_variable = ctk.StringVar(value=Font) # 默认选择与appearance_color相同的选项
# 创建下拉菜单
font_dropdown = ctk.CTkOptionMenu(
Meaning_Bar_right,
variable=font_variable,
values=font_options,
command=lambda event: update_appearance_mode(font_variable.get()),
)
font_dropdown.place(x=115, y=100)
#________________________________________
else:
Meaning_Bar_right = ctk.CTkFrame(Opendict, width=470, height=540, corner_radius=20)
Meaning_Bar_right.place(x=520, y=40)
if translate_button_clicked:
Meaning_Bar_right.destroy()
Meaning_Bar_right = ctk.CTkFrame(Opendict, width=470, height=540, corner_radius=20)
Meaning_Bar_right.place(x=520, y=40)
Settings_button = ctk.CTkButton(Opendict, width=50, text="⚙️Settings", command=settings_button_clicked)
Settings_button.pack(side="right", padx=6, pady=5, anchor=tkinter.NE)
#————————————————————————dictionary settings————————————————————————————————————
Dictinaries_button = ctk.CTkButton(Opendict, width=60, text="📖Dictionaries", command=search)
Dictinaries_button.pack(side="right", padx=5, pady=5, anchor=tkinter.NE)
#————————————————————————translate settings————————————————————————————————————
is_translate_button_clicked = False # 初始化布尔变量
def translate_button_clicked():
global is_translate_button_clicked, Meaning_Bar_right
is_translate_button_clicked = not is_translate_button_clicked # 切换状态
if is_translate_button_clicked:
# 缩小 Meaning_Bar_right
Meaning_Bar_right.place_forget()
Meaning_Bar_right = ctk.CTkFrame(Opendict, width=470, height=540, corner_radius=20)
Meaning_Bar_right.place(x=520, y=40)
Meaning_Bar_right.destroy()
Meaning_Bar_right_1 = ctk.CTkFrame(Opendict, width=470, height=230, corner_radius=20)
Meaning_Bar_right_1.place(x=520, y=75)
Meaning_Bar_right_2 = ctk.CTkFrame(Opendict, width=470, height=265, corner_radius=20)
Meaning_Bar_right_2.place(x=520, y=315)
Translate_API = ctk.CTkEntry(Opendict, width=200, placeholder_text="Enter your Translator API")
Translate_API.place(x=520, y=40)
else:
# 恢复 Meaning_Bar_right 到原样
Meaning_Bar_right.destroy()
Meaning_Bar_right = ctk.CTkFrame(Opendict, width=470, height=540, corner_radius=20)
Meaning_Bar_right.place(x=520, y=40)
Dictinaries_button = ctk.CTkButton(Opendict, width=60, text="🛃Translation", command=translate_button_clicked)
Dictinaries_button.pack(side="right", padx=5, pady=5, anchor=tkinter.NE)
#——————————————————————————页面————————————————————————————————————
Meaning_Bar_left = ctk.CTkFrame(Opendict, width=500, height=540, corner_radius=20)
Meaning_Bar_left.place(x=10, y=40)
# 添加文字标签
meaning_label = ctk.CTkLabel(Meaning_Bar_left, text="↓Meaning↓", font=(str(Font), 16, "bold"), text_color="white", bg_color="transparent")
meaning_label.place(x=15, y=10) # 放置在 Meaning_Bar_left 上方
# 这里需要先创建 Meaning_Bar_right,因为在 translate_button_clicked 函数中会使用它
global Meaning_Bar_right
Meaning_Bar_right = ctk.CTkFrame(Opendict, width=460, height=535, corner_radius=20)
Meaning_Bar_right.place(x=520, y=40)
def update_appearance_mode(new_mode):
global appearance_color
appearance_color = new_mode
customtkinter.set_appearance_mode(new_mode)
def update_font_style(new_mode):
global Font
Font = Font
Opendict.update()
Opendict.mainloop()
Last edited by a moderator: