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,但如果你做下面的代碼Tkinter的網格和框架沒有調整大小框架
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 = [self.frame,self.input_text]替換't = ['frame,input_text']' '和'我()'的eval語句。此外,你不需要Python中的分號。這是unpythonic。 – arkocal
你的問題很難理解。這兩個例子都不能像你想要的那樣工作,或者只有第一個例子? –