在Python编辑器中锁定文字?并将文本锁定在Python边界内?

时间:2018-08-28 00:30:25

标签: python python-3.x tkinter

我在编码中写了一些Lorum Ipsum填充词来测试这些词,但是我遇到了两个明显的问题,即词没有走到另一条整齐的线。我在代码编辑器简洁性和程序本身方面都遇到了问题。下面,我将写下编辑器和程序中目前存在的所有问题。

编辑器问题:我不确定如何使编辑器将这些单词锁定在编辑器的边界内,而不是进入无法向左滚动才能回到原始位置的非常长的一行码。我没有在编辑器上找到任何可将单词推回编辑器左侧的内容。我正在使用IDLE编辑器,但是我找不到找到将单词推回左侧的函数,但是当我使用HTML时,可以使用Notepad ++很好地找到它。而且我不知道如何使用Notepad ++编写Python代码,而是宁愿继续使用IDLE编辑器。

程序GUI问题:在我制作的Tkinter GUI的整个960px整齐的程序中,Lorum Ipsum单词没有锁定在一起。我不知道该如何解决。当我尝试使用“ .grid”函数而不是“ .pack”函数时,如果我还尝试在其下放置一个图形,则会出现错误。当我尝试使用“ .pack”函数时,它不会出错,但是这些单词并没有像预期的那样锁定在程序的边界内,而是将这些单词仅放在一行的中心。

import tkinter as tk
from tkinter import *

root = tk.Tk()
root.geometry("960x600")

label_toptitle = tk.Label(root,
                      text="Program Name",
                      font=(None, 40),
)
label_toptitle.pack(side="top", fill="x")

label_desc = Label(root,
               text="Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,",
               bd=1,
               #relief="solid",
               font=(None, 20),
               padx=20,
               pady=10)
label_desc.pack(side="top", fill="x")
##label_desc.grid(row=0,
##                #sticky=E
##                )

canvas = Canvas(width=960, height=300, bg='white')
canvas.pack(expand=YES, fill=BOTH)

canvas.create_rectangle(278, 20, 664, 114, width=5, fill='pink')
canvas.create_rectangle(70, 140, 888, 284, width=5, fill='pink')
canvas.create_rectangle(70, 318, 888, 408, width=5, fill='pink')
canvas.create_rectangle(257, 468, 349, 557, width=5, fill='pink')
canvas.create_rectangle(430, 468, 520, 557, width=5, fill='pink')
canvas.create_rectangle(597, 468, 689, 557, width=5, fill='pink')

root.mainloop()

0 个答案:

没有答案