7

How do i increase or define window size of tkSimpleDialog box ?

import Tkinter, tkSimpleDialog
root = Tkinter.Tk()
root.withdraw()
test = tkSimpleDialog.askstring("testing", "Enter your search string text")
print test
Shekhar Samanta
  • 875
  • 2
  • 12
  • 25

4 Answers4

8

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")
print test
Pang
  • 9,564
  • 146
  • 81
  • 122
Yitbareck
  • 87
  • 2
  • 4
  • Note: you can use white space for this, e.g. `rPadChars = 50 * " "` and then just `prompt + rPadChars` – BuvinJ Feb 10 '21 at 16:53
4

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

import Tkinter as tk, tkSimpleDialog

class MyDialog(tkSimpleDialog.Dialog):
    def body(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 focus

    def apply(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).

Eric Levieil
  • 3,554
  • 2
  • 13
  • 18
1

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

def buttonbox(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()
ugur
  • 33
  • 9
-1

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()
print test
AndresJ
  • 51
  • 5