增加 tkSimpleDialog window 大小
Increase tkSimpleDialog window size
如何增加或定义 window tkSimpleDialog 框的大小?
import Tkinter, tkSimpleDialog
root = Tkinter.Tk()
root.withdraw()
test = tkSimpleDialog.askstring("testing", "Enter your search string text")
print test
tkSimpleDialog 不允许您更改它的几何形状
仅就地使用 Tk()
这里有一个示例,您可以在其中看到两者之间的区别 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
开始于:http://effbot.org/tkinterbook/tkinter-dialog-windows.htm
我做了以下事情:
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
如果您想要自定义几何图形和标签的文本,您可能需要覆盖 __init__
(link 中给出的版本应该是一个很好的起点)。
将第二个参数设置成你喜欢的大小:
import Tkinter, tkSimpleDialog
root = Tkinter.Tk()
root.withdraw()
test = tkSimpleDialog.askstring("testing", "Enter your search string text in the space provided")
print test
如果你想要更宽的框,你可以从源代码中使按钮更宽,或者在你的代码中覆盖它:
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()
如何增加或定义 window tkSimpleDialog 框的大小?
import Tkinter, tkSimpleDialog
root = Tkinter.Tk()
root.withdraw()
test = tkSimpleDialog.askstring("testing", "Enter your search string text")
print test
tkSimpleDialog 不允许您更改它的几何形状
仅就地使用 Tk()
这里有一个示例,您可以在其中看到两者之间的区别 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
开始于:http://effbot.org/tkinterbook/tkinter-dialog-windows.htm 我做了以下事情:
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
如果您想要自定义几何图形和标签的文本,您可能需要覆盖 __init__
(link 中给出的版本应该是一个很好的起点)。
将第二个参数设置成你喜欢的大小:
import Tkinter, tkSimpleDialog
root = Tkinter.Tk()
root.withdraw()
test = tkSimpleDialog.askstring("testing", "Enter your search string text in the space provided")
print test
如果你想要更宽的框,你可以从源代码中使按钮更宽,或者在你的代码中覆盖它:
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()