Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 your search string text")
print test
like image 546
Shekhar Samanta Avatar asked Oct 29 '15 14:10

Shekhar Samanta


3 Answers

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
like image 74
Yitbareck Avatar answered Nov 15 '22 20:11

Yitbareck


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).

like image 24
Eric Levieil Avatar answered Nov 15 '22 21:11

Eric Levieil


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()
like image 1
ugur Avatar answered Nov 15 '22 21:11

ugur