TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
11.33k stars 1.07k forks source link

CTkInputDialog: add the ability to edit the Ok button and Cancel button. #1826

Open utsiye opened 1 year ago

utsiye commented 1 year ago

I'm writing a program, not in English. So I can't use inputdialog right now. It would be cool if there was such a function.

ghost commented 1 year ago

You could try to replicate the input dialog with CTkToplevel. This would allow you to use any language you want (through labels and buttons).

utsiye commented 1 year ago

You could try to replicate the input dialog with CTkToplevel. This would allow you to use any language you want (through labels and buttons).

Yes, but the idea of inputdialog is to shorten the code and replace some toplevel.

ghost commented 1 year ago

True, so every other widget's text can be customized right? If not, it would mean that every widget needs customizable text for the multilingual support.

utsiye commented 1 year ago

True, so every other widget's text can be customized right? If not, it would mean that every widget needs customizable text for the multilingual support.

No, if there will be more widgets like selecting YES/NO in toplevel or other things, for them, yes. Some frame doesn't have text, so you don't need the text option.

zhongyupei666 commented 8 months ago

so , what is the solution to this Issue?

ghost commented 8 months ago

Implementation of my idea from this comment.

I've provided some example code to show how one can replicate the CTkInputDialog. It makes use of CTkButtons which allow for strings to set the text. Since many languages are included in Unicode and other fonts, you can use these in the string for the button's text. In the example I have English and Hindi.

import customtkinter as ctk

app = ctk.CTk()

app.geometry("200x100")
app.title("Solution")

def okay_command():
    print("Okay")

def cancel_command():
    print("Cancel")

def openPopup():
    popup = ctk.CTkToplevel()
    popup.title("Popup")

    okay_button = ctk.CTkButton(master = popup,
                                text = "Okay - ठीक है",
                                command = okay_command
                                )
    okay_button.pack(padx = 10, pady = 10)

    cancel_button = ctk.CTkButton(master = popup,
                                text = "Cancel - रद्द करना",
                                command = cancel_command
                                )
    cancel_button.pack(padx = 10, pady = 10)

button = ctk.CTkButton(master = app, text = "Click me!", command = openPopup)
button.pack(padx = 10, pady = 10)

if __name__ == "__main__":
    app.mainloop()

The example is NOT completed to take user input. For that, you'll have to add to the code a CTkEntry and a StringVar to manage the state/text entered into the CTkEntry.

This is a temporary solution because it uses more code and basically renders CTkInputDialog obsolete.

zhongyupei666 commented 8 months ago

this is a good idea.

光海 @.***

---Original--- From: "Dishant @.> Date: Tue, Jan 23, 2024 04:00 AM To: @.>; Cc: @.**@.>; Subject: Re: [TomSchimansky/CustomTkinter] CTkInputDialog: add the ability toedit the Ok button and Cancel button. (Issue #1826)

I've provided some example code to show how one can replicate the CTkInputDialog. It makes use of CTkButtons which allow for strings to set the text. Since many languages are included in Unicode and other fonts, you can use these in the string for the button's text. In the example I have English and Hindi. import customtkinter as ctk app = ctk.CTk() app.geometry("200x100") app.title("Solution") def okay_command(): print("Okay") def cancel_command(): print("Cancel") def openPopup(): popup = ctk.CTkToplevel() popup.title("Popup") okay_button = ctk.CTkButton(master = popup, text = "Okay - ठीक है", command = okay_command ) okay_button.pack(padx = 10, pady = 10) cancel_button = ctk.CTkButton(master = popup, text = "Cancel - रद्द करना", command = cancel_command ) cancel_button.pack(padx = 10, pady = 10) button = ctk.CTkButton(master = app, text = "Click me!", command = openPopup) button.pack(padx = 10, pady = 10) if name == "main": app.mainloop()

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>