增加tkSimpleDialog窗口大小

时间:2015-10-29 14:48:16

标签: python python-2.7 tkinter tkinter-canvas

如何增加或定义tkSimpleDialog框的窗口大小?

import Tkinter, tkSimpleDialog
root = Tkinter.Tk()
root.withdraw()
test = tkSimpleDialog.askstring("testing", "Enter your search string text")
print test

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:-1)

tkSimpleDialog不允许您更改它的几何

仅使用Tk()

这里有一个例子,你可以看到两个窗口之间的区别

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

答案 2 :(得分:-1)

使第二个参数尽可能大:

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