how to modify the background color of a python simpledialog widget

18 Views Asked by At

I have a simpledialog.askstring('x','Input number of stars to award the category:\t\t\t') x is the category name. I would like the simpledialog that pops up to have a different background color. Also I would like to control where the pop up appears on the screen because it sometimes appears behind other python forms.

At this point I am trying to do as much research about using the simpledialog functionality

1

There are 1 best solutions below

0
SlimiBoy On

I do not know how to set, where the pop up appears on screen, but for the backgroun color you could subclass simpledialog.Dialog:

import tkinter as tk
from tkinter import simpledialog

class CustomAskStringDialog(simpledialog.Dialog):
    def body(self, master):
        self.title("different background color")
        tk.Label(master, text="Input number of stars to award the categorry:/t/t/t").grid(row=0, sticky=tk.W)
        self.entry = tk.Entry(master)
        self.entry.grid(row=0, column=1)
        return self.entry

    def apply(self):
        self.result = self.entry.get()

def ask_string_with_bg_color():
    root = tk.Tk()
    root.withdraw()

    root.tk_setPalette(background='#b80300')

    dialog = CustomAskStringDialog(root, "different background color")
    result = dialog.result
    root.destroy()
    return result

result = ask_string_with_bg_color()
print("User input:", result)