\n
This is my Procedure method -\nOnce the procedure is collected it is stored into a dictionary
\n def Procedure(self):\n\n textfield = Text(gui, height=30, width=82)\n textfield.place(x="20", y="100")\n\n procedure_label = LabelWidget(self.screen, "Procedure", "Courier", 40)\n procedure_label.Call().place(x="220", y="20")\n\n button_save = Button(gui, text="Next", padx="50", pady="20", bg="lightgrey",\n command=partial(self.CheckPage, 4, procedure=textfield))\n button_save.place(x="250", y="600")\n
\nThis is how I'm printing my proceudre
\n proc_text_label = ""\n for i in fullDictProc:\n proc_text_label_temp = Label(root, text=i, wraplength=900)\n proc_text_label = proc_text_label_temp\n proc_text_label.config(font=("Courier", 12))\n proc_text_label.place(x=70, y=250)\n
\nRun it and see the alignment of the text.
\nfrom tkinter import *\nfrom functools import partial\n\ngui = Tk()\ngui.geometry("700x700")\n\n\ndef printit(textfield):\n procedure_list = [textfield.get("1.0", "end-1c")]\n textfield.place_forget()\n proc_text_label = ""\n for i in procedure_list:\n proc_text_label_temp = Label(gui, text=i, wraplength=900)\n proc_text_label = proc_text_label_temp\n proc_text_label.config(font=("Courier", 12))\n proc_text_label.place(x=70, y=250)\n\n\ntextfield = Text(gui, height=30, width=82)\ntextfield.place(x="20", y="100")\n\n\nbutton_save = Button(gui, text="Next", padx="50", pady="20", bg="lightgrey",\n command=partial(printit, textfield))\n\nbutton_save.place(x=500, y=600)\ngui.mainloop()\n
\n","author":{"@type":"Person","name":"rishi"},"upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"I think what you are looking for might be justify
:
proc_text_label.config(justify='left')\n
\nHave a look at The Tkinter Label Widget
\n","author":{"@type":"Person","name":"figbeam"},"upvoteCount":3}}}Reputation: 640
In my tkinter program I'm collecting text from the user using Text
widget, this is later printed on the screen using a label
widget. Although I'm able to print it onto the screen, the text is all center aligned. Since what I'm collecting is a procedure for something it gets difficult to read, so I need it to be left aligned.
This is my Procedure method - Once the procedure is collected it is stored into a dictionary
def Procedure(self):
textfield = Text(gui, height=30, width=82)
textfield.place(x="20", y="100")
procedure_label = LabelWidget(self.screen, "Procedure", "Courier", 40)
procedure_label.Call().place(x="220", y="20")
button_save = Button(gui, text="Next", padx="50", pady="20", bg="lightgrey",
command=partial(self.CheckPage, 4, procedure=textfield))
button_save.place(x="250", y="600")
This is how I'm printing my proceudre
proc_text_label = ""
for i in fullDictProc:
proc_text_label_temp = Label(root, text=i, wraplength=900)
proc_text_label = proc_text_label_temp
proc_text_label.config(font=("Courier", 12))
proc_text_label.place(x=70, y=250)
Run it and see the alignment of the text.
from tkinter import *
from functools import partial
gui = Tk()
gui.geometry("700x700")
def printit(textfield):
procedure_list = [textfield.get("1.0", "end-1c")]
textfield.place_forget()
proc_text_label = ""
for i in procedure_list:
proc_text_label_temp = Label(gui, text=i, wraplength=900)
proc_text_label = proc_text_label_temp
proc_text_label.config(font=("Courier", 12))
proc_text_label.place(x=70, y=250)
textfield = Text(gui, height=30, width=82)
textfield.place(x="20", y="100")
button_save = Button(gui, text="Next", padx="50", pady="20", bg="lightgrey",
command=partial(printit, textfield))
button_save.place(x=500, y=600)
gui.mainloop()
Upvotes: 1
Views: 804
Reputation: 7176
I think what you are looking for might be justify
:
proc_text_label.config(justify='left')
Have a look at The Tkinter Label Widget
Upvotes: 3
Reputation: 305
I think what you're looking for is the anchor parameter. This is how it worked with your minimal example:
from tkinter import *
from functools import partial
gui = Tk()
gui.geometry("700x700")
def printit(textfield):
procedure_list = [textfield.get("1.0", "end-1c")]
textfield.place_forget()
proc_text_label = ""
for i in procedure_list:
proc_text_label_temp = Label(gui, text=i, wraplength=900,
anchor='w',
bg='blue',
width=50)
proc_text_label = proc_text_label_temp
proc_text_label.config(font=("Courier", 12))
proc_text_label.place(x=70, y=250)
textfield = Text(gui, height=30, width=82)
textfield.place(x="20", y="100")
button_save = Button(gui, text="Next", padx="50", pady="20", bg="lightgrey",
command=partial(printit, textfield))
button_save.place(x=500, y=600)
gui.mainloop()
Upvotes: 1