Skip to content Skip to sidebar Skip to footer

Increase Tksimpledialog Window Size

How do i increase or define window size of tkSimpleDialog box ? import Tkinter, tkSimpleDialog root = Tkinter.Tk() root.withdraw() test = tkSimpleDialog.askstring('testing', 'Enter

Solution 1:

Make the second parameter as big as you like:

import Tkinter, tkSimpleDialog
root = Tkinter.Tk()
root.withdraw()
test = tkSimpleDialog.askstring("testing", "Enter your search string text in the space provided")
printtest

Solution 2:

Starting from: http://effbot.org/tkinterbook/tkinter-dialog-windows.htm I did the following:

import Tkinter as tk, tkSimpleDialog

classMyDialog(tkSimpleDialog.Dialog):
    defbody(self, master):
        self.geometry("800x600")
        tk.Label(master, text="Enter your search string text:").grid(row=0)

        self.e1 = tk.Entry(master)
        self.e1.grid(row=0, column=1)
        return self.e1 # initial focusdefapply(self):
        first = self.e1.get()
        self.result = first


root = tk.Tk()
root.withdraw()
test = MyDialog(root, "testing")
print test.result

If you want geometry and the label's text to be customizable, you will probably need to override __init__ (the version given in the link should be a good starting point).

Solution 3:

If you want to wider box you can make buttons wider from the source code or override it inside your code:

defbuttonbox(self):
    '''add standard button box.

    override if you do not want the standard buttons
    '''

    box = Frame(self)

    w = Button(box, text="OK", width=100, command=self.ok, default=ACTIVE)
    w.pack(side=LEFT, padx=5, pady=5)
    w = Button(box, text="Cancel", width=100, command=self.cancel)
    w.pack(side=LEFT, padx=5, pady=5)

    self.bind("<Return>", self.ok)
    self.bind("<Escape>", self.cancel)

    box.pack()

Solution 4:

tkSimpleDialog doesn't allows you to change it's geometry

In place use Tk() only

Here you have an exmple where you'll see the difference between two windows

import Tkinter, tkSimpleDialog

root = Tkinter.Tk()
root.geometry('240x850+200+100')
#root.withdraw()test = tkSimpleDialog.askstring("testing", "Enter your search string text")
root.mainloop()
printtest

Post a Comment for "Increase Tksimpledialog Window Size"