【发布时间】:2014-02-06 23:15:16
【问题描述】:
class input_data(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self);
self.resizable(width=False,height=False);
self.geometry('500x500');
t = ['frame','input_text'];
for i in t:
eval('self.'+i+'()');
def frame(self):
self.f = Tkinter.Frame(self,width=200,height=200,bg='cyan');
self.f.grid(row=0,column=0);
def input_text(self):
self.e = Tkinter.Entry(self.f);
self.e.grid(row=0,column=0);
root = input_data();
root.mainloop();
代码看起来不错,但框架不符合指示的 dedida,但如果符合,请在以下代码中
import Tkinter as tk
class SimpleApp(object):
def __init__(self, master, **kwargs):
title = kwargs.pop('title')
frame = tk.Frame(master, borderwidth=5, bg = 'cyan', **kwargs)
frame.grid()
button = tk.Button(frame, text = title)
button.grid(sticky = tk.SE)
frame.rowconfigure('all', minsize = 200)
frame.columnconfigure('all', minsize = 200)
def basic():
root = tk.Tk()
app = SimpleApp(root, title = 'Hello, world')
root.mainloop()
basic()
我未能使第一个代码的宽度和高度不起作用
【问题讨论】:
-
我不知道是什么导致了这个问题,但我会将
t = ['frame, input_text']替换为t = [self.frame, self.input_text]并将eval 语句替换为i()。此外,您在 python 中不需要分号。这是unpythonic。 -
你的问题很难理解。这两个示例都无法按您的意愿工作,还是只有第一个?
-
接下来,您可以在提交之前阅读您的问题名称吗?这是一个经过深思熟虑的问题,但标题真的很难找到。