【发布时间】:2018-11-30 17:32:21
【问题描述】:
我可以在我的 tkinter 程序中使用 defaultdict 选择行,但我不知道如何选择整个列。我了解 defaultdict(list) 的概念,但我不知道如何编写代码来选择一列。 defaultdict 设置发生在一个更大的程序的一部分,所以我必须使用这个设置。如果有人可以帮助我选择列,将不胜感激。以我有限的知识,我知道要访问字典值我需要有 [][] 来访问它的值,我会将它放在我的代码中的什么位置?例如,如果我想将红色放在列 [1] 中,我该怎么做?
import pulp
import tkinter as tk
from tkinter import ttk
from collections import defaultdict
class Application(ttk.Frame): #inherent from frame.
def __init__(self, parent):
tk.Frame.__init__(self, parent, bg="LightBlue4")
self.parent = parent
self.pack()
self.labels_dict = defaultdict(list)
self.GUI()
def GUI(self):
for i in range (9):
for day in range(7):
self.label = tk.Label(self, relief="ridge", width=11,
height=3)
self.label.grid(row=i, column=day, sticky='nsew')
self.labels_dict[i].append(self.label)
self.button=tk.Button(self, text="Caluculate", bg="salmon")
self.button.grid(row = 10, column = 6)
for (i) in self.labels_dict:
for element in self.labels_dict[1]:
element.configure(bg = "red")
def main():
root = tk.Tk()
root.title("class basic window")
root.geometry("1200x600")
root.config(background="LightBlue4")
app = Application(root)
root.mainloop()
if __name__ == '__main__':
main()
【问题讨论】:
标签: python python-3.x tkinter selection defaultdict