簡體   English   中英

從列表打印 TKinter

[英]printing from a list TKinter

試圖打印 tkinter 網格第 0 列的列表中的月份。 但是 output 是在一個單元格中重疊打印。 無法找出問題所在。

#!/bin/env /python
from Tkinter import *

akhilGui = Tk()
akhilGui.geometry('600x500')
month_list = ["April 2020","May 2020","June 2020", "july 2020","August 2020", "September 2020","October 2020","November2020", "December 2020", "January 2020","February 2020", "March 2020"] #initialise the variable row_value to be used in grid()
lab_list = []
def lab_print ():
        for i in month_list:                        #iterating through the list, creating label
        #iLabel          = str(i) + "Label"
        #iEntry          = str(i) + "Entry"
            row_value = 5
            row_value = row_value + 1
            iLabel          = Label(akhilGui, text= str(i),
                                fg="#113B53",font = "Helvetica  12 bold ", justify='right')
            lab_list.append(iLabel)
            iLabel.grid(row = row_value, column=0, pady=2, padx=15, sticky= W)

lab_print ()


akhilGui.mainloop()

您應該在 for 循環之前移動行row_value = 5

def lab_print ():
        row_value = 5
        for i in month_list:   #iterating through the list, creating label
            row_value = row_value + 1
            iLabel = Label(akhilGui, text= str(i),
                                fg="#113B53",font = "Helvetica  12 bold ", justify='right')
            lab_list.append(iLabel)
            iLabel.grid(row = row_value, column=0, pady=2, padx=15, sticky= W)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM