Increase tkSimpleDialog window size
Asked Answered
G

4

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
Gloze answered 29/10, 2015 at 14:48 Comment(0)
H
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).

Hendecahedron answered 29/10, 2015 at 15:43 Comment(0)
A
9

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
Abamp answered 18/5, 2017 at 8:6 Comment(1)
Note: you can use white space for this, e.g. rPadChars = 50 * " " and then just prompt + rPadCharsNiacin
H
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).

Hendecahedron answered 29/10, 2015 at 15:43 Comment(0)
O
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()
Octogenarian answered 16/10, 2021 at 19:20 Comment(0)
D
-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
Dierdredieresis answered 29/10, 2015 at 15:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.