我想为Tkinter添加10个按钮,名为One to Ten.我基本上只使用了暴力方法,在我的应用程序类的init函数中添加每个按钮.它可以工作,但我想最小化所使用的代码,以提高效率,例如使用数据结构来保存所有按钮.
我正在考虑使用a buttonBox来容纳所有按钮,但我不确定我是否可以通过操作grid()按钮放置按钮我想要的方式.
self.one = Button(frame, text="One", command=self.callback)
self.one.grid(sticky=W+E+N+S, padx=1, pady=1)
self.two = Button(frame, text="Two", command=self.callback)
self.two.grid(sticky=W+E+N+S, row=0, column=1, padx=1, pady=1)
self.three = Button(frame, text="Three", command=self.callback)
self.three.grid(sticky=W+E+N+S, row=0, column=2, padx=1, pady=1)
# ...
self.ten = Button(frame, text="Ten", command=self.callback)
self.ten.grid(sticky=W+E+N+S, row=1, column=4, padx=1, pady=1)
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我一种提高效率的方法,比如数据结构吗?
这个代码中的&符号是什么意思?
int clothes = (random.nextInt(0x1000000) & 0x7f7f7f);
Run Code Online (Sandbox Code Playgroud) 研究人员拥有1亿人的记录数据库.研究人员希望根据其他标准(如星座,出生年份等)研究给定名称的分布,因此希望按名称排序,以后再进行进一步排序.
我应该使用哪种?
A.选择
B.快速
C.堆
D.插入
E.合并
谢谢!
(代码约定doc:http://www.oracle.com/technetwork/java/codeconventions-142311.html#449)
我总是把if-else语句写成:
if(condition) {
statements;
} else {
statements;
}
Run Code Online (Sandbox Code Playgroud)
但是,在Java代码约定文档中,它表示如下所示:
if (
condition) {
statements;
} else {
statements;
}
Run Code Online (Sandbox Code Playgroud)
而且,我总是写这样的陈述:
for(initialization;condition;update) {
statements;
}
Run Code Online (Sandbox Code Playgroud)
但编码惯例说:
for (
initialization;
condition;
update) {
statements;
}
Run Code Online (Sandbox Code Playgroud)
压痕和间距对我来说似乎不必要的麻烦.哪个是正确/更好的方式,为什么?
java ×3
algorithm ×1
ampersand ×1
button ×1
conventions ×1
declaration ×1
for-loop ×1
if-statement ×1
python ×1
sorting ×1
tkinter ×1
variables ×1