Best Module to Layout Text in Python -
i looking write program outputs bunch (around 30) of boxes in image:
i have been reasearching weeks, thought layout text in graphically pleasing way use qtablewidget in pyqt, realise far difficult learn such simple task, there must quicker way. thinking pass tkinter or maybe draw informations drawing module pycairo , place each image in pyqt interface. sorting out positioning in drawing module quicker learning how same in pyqt.
but feel missing something, woudl have thought easier task layout in nice way bunch of numbers in repetitive format.
some of boxes need graphical content has bars , charts though use plotly or cairo.
whilst you're better off doing html , css has been mentioned above, isn't difficult python , can achieved use of tkinter
. please see code below example of how work:
from tkinter import * root = tk() frame1 = [] frame2 = [] c = 0 numberofboxes = 8 #change increase number of boxes in range(numberofboxes): if % 4 == 0: #checks if current box fourth in row c = c + 1 #if current box forth in row runs , increases counter later use determine row if len(frame1) != c: #checks if number of rows existing matches number there should frame1.append(frame(root)) #if numbers don't match runs , creates new frame acts row frame1[c-1].pack(expand="true", fill="both") #packs new row frame2.append(frame(frame1[c-1], bg="green")) #this boxes created frame2[i].pack(ipadx="50", ipady="50", side="left", padx="10", pady="10", expand="true", fill="both") #this boxes placed on screen in range(len(frame2)): #this loop places items inside each box, of can replaced whatever needed label(frame2[i], text="co"+str(i), bg="green", fg="white").pack(side="top", anchor="w") label(frame2[i], text="12165.1"+str(i), bg="green", fg="white").pack(side="top", anchor="w") label(frame2[i], text="+60.7"+str(i), bg="green", fg="white").pack(side="bottom", anchor="e") label(frame2[i], text="+1.2"+str(i)+"%", bg="green", fg="white").pack(side="bottom", anchor="e") root.mainloop()
so essentially, create frame
each row , each box frame
has elements packed inside , fitted in "row frame
" 4 each row.
you should take close @ of options .pack()
during script necessary achieve desired layout , results.
for triangles need either import image or draw them within canvas
positioned or (as pointed out bryan oakley below) use unicode characters arrows, awful lot simpler.
Comments
Post a Comment