Hướng dẫn python print text in a box - python in văn bản trong hộp

Dưới đây là một chức năng được xây dựng nhẹ để in hộp thư với tiêu đề và thụt đầu tư tùy chọn xoay quanh dòng dài nhất:

def print_msg_box(msg, indent=1, width=None, title=None):
    """Print message-box with optional title."""
    lines = msg.split('\n')
    space = " " * indent
    if not width:
        width = max(map(len, lines))
    box = f'╔{"═" * (width + indent * 2)}╗\n'  # upper_border
    if title:
        box += f'║{space}{title:<{width}}{space}║\n'  # title
        box += f'║{space}{"-" * len(title):<{width}}{space}║\n'  # underscore
    box += ''.join([f'║{space}{line:<{width}}{space}║\n' for line in lines])
    box += f'╚{"═" * (width + indent * 2)}╝'  # lower_border
    print(box)

Demo:

print_msg_box('\n~ PYTHON ~\n')
╔════════════╗
║            ║
║ ~ PYTHON ~ ║
║            ║
╚════════════╝
print_msg_box('\n~ PYTHON ~\n', indent=10)
╔══════════════════════════════╗
║                              ║
║          ~ PYTHON ~          ║
║                              ║
╚══════════════════════════════╝
print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
╔════════════════════════════════════════╗
║                                        ║
║          ~ PYTHON ~                    ║
║                                        ║
╚════════════════════════════════════════╝
msg = "And I thought to myself,\n" \
      "'a little fermented curd will do the trick',\n" \
      "so, I curtailed my Walpoling activites, sallied forth,\n" \
      "and infiltrated your place of purveyance to negotiate\n" \
      "the vending of some cheesy comestibles!"

print_msg_box(msg=msg, indent=2, title='In a nutshell:')
╔══════════════════════════════════════════════════════════╗
║  In a nutshell:                                          ║
║  --------------                                          ║
║  And I thought to myself,                                ║
║  'a little fermented curd will do the trick',            ║
║  so, I curtailed my Walpoling activites, sallied forth,  ║
║  and infiltrated your place of purveyance to negotiate   ║
║  the vending of some cheesy comestibles!                 ║
╚══════════════════════════════════════════════════════════╝


Chúng ta có thể sử dụng tiện ích văn bản Tkinter để chèn văn bản, hiển thị thông tin và lấy đầu ra từ tiện ích văn bản. Để có được đầu vào của người dùng trong tiện ích văn bản, chúng tôi đã sử dụng phương thức get (). Hãy lấy một ví dụ để xem nó hoạt động như thế nào.get() method. Let's take an example to see how it works.

Thí dụ

# Import the required library
from tkinter import *
from tkinter import ttk

# Create an instance of tkinter frame
win=Tk()

# Set the geometry
win.geometry("700x350")

def get_input():
   label.config(text=""+text.get(1.0, "end-1c"))

# Add a text widget
text=Text(win, width=80, height=15)
text.insert(END, "")
text.pack()

# Create a button to get the text input
b=ttk.Button(win, text="Print", command=get_input)
b.pack()

# Create a Label widget
label=Label(win, text="", font=('Calibri 15'))
label.pack()

win.mainloop()

Đầu ra

Chạy mã trên sẽ hiển thị một cửa sổ chứa tiện ích văn bản. Nhập một cái gì đó vào tiện ích văn bản và nhấp vào nút "In" để hiển thị đầu ra."Print" button to display the output.

Hướng dẫn python print text in a box - python in văn bản trong hộp

Hướng dẫn python print text in a box - python in văn bản trong hộp

Cập nhật ngày 05 tháng 8 năm 2021 14:29:33

  • Câu hỏi và câu trả lời liên quan
  • Làm thế nào để tôi tập trung văn bản trong một tiện ích văn bản tkinter?
  • Làm thế nào để lấy đầu vào trong một tiện ích văn bản và hiển thị văn bản trong tkinter?
  • Làm thế nào để tôi tập trung vào một tiện ích văn bản Python Tkinter?
  • Làm thế nào để có hình ảnh và văn bản trong một nút trong tkinter?
  • Lấy đầu vào từ người dùng trong tkinter
  • Làm cách nào để tạo một hộp tin nhắn đơn giản trong tkinter?
  • Làm thế nào để đặt biện minh trên hộp văn bản tkinter?
  • Python Tkinter - Làm cách nào để thay đổi kích thước văn bản trong tiện ích nhãn?
  • Chỉ định kích thước của hộp văn bản tkinter tính bằng pixel
  • Làm cách nào để đóng cửa sổ tkinter?
  • Làm thế nào để hiển thị latex trong thời gian thực trong hộp văn bản trong tkinter?
  • Làm thế nào để chèn văn bản ở đầu hộp văn bản trong tkinter?
  • Làm cách nào để hiển thị các chú giải công cụ trong tkinter?
  • Làm thế nào để xóa nội dung hộp văn bản tkinter?
  • Làm cách nào để tạo một người chọn ngày trong tkinter?

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc
    Note: For more information, refer to Python GUI – tkinter
     

    Bàn luận

    Tkinter là một bộ công cụ GUI được sử dụng trong Python để làm cho GUI thân thiện với người dùng. Tkinter sử dụng cách tiếp cận hướng đối tượng để tạo GUI.note: Để biết thêm thông tin, hãy tham khảo Python GUI-Tkinter & NBSP;
    Syntax: 
     

    print_msg_box('\n~ PYTHON ~\n')
    
    0

    Tiện ích văn bản 
     

    • Tiện ích văn bản được sử dụng khi người dùng muốn chèn các trường văn bản đa dòng. Tiện ích này có thể được sử dụng cho một loạt các ứng dụng trong đó văn bản đa dòng được yêu cầu như nhắn tin, gửi thông tin hoặc hiển thị thông tin và nhiều tác vụ khác. Chúng ta cũng có thể chèn các tệp phương tiện như hình ảnh và liên kết trong textwidget.syntax: & nbsp; & nbsp; – root window. 
       
    • Tham số tùy chọn & nbsp; & nbsp; – background colour 
       
    • root - cửa sổ gốc. & nbsp; & nbsp; – foreground colour 
       
    • BG - Màu nền & nbsp; & nbsp; – border of widget. 
       
    • FG - Màu tiền cảnh & nbsp; & nbsp; – height of the widget. 
       
    • BD - biên giới của Widget. & nbsp; & nbsp; – width of the widget. 
       
    • chiều cao - chiều cao của tiện ích. & nbsp; & nbsp; – Font type of the text. 
       
    • chiều rộng - chiều rộng của tiện ích. & nbsp; & nbsp; – The type of the cursor to be used. 
       
    • Phông chữ - loại phông chữ của văn bản. & nbsp; & nbsp; – The time in milliseconds for which the cursor blink is off. 
       
    • con trỏ - loại con trỏ sẽ được sử dụng. & nbsp; & nbsp; – the time in milliseconds for which the cursor blink is on. 
       
    • INSETOFFTIME - Thời gian tính bằng mili giây mà con trỏ nhấp nháy. & NBSP; & nbsp; – horizontal padding. 
       
    • InserTontime - Thời gian tính bằng mili giây mà con trỏ nhấp nháy. & NBSP; & nbsp; – vertical padding. 
       
    • padx - đệm ngang. & nbsp; & nbsp; – defines if the widget will be responsive to mouse or keyboards movements. 
       
    • Pady - Đệm dọc. & NBSP; & nbsp; – defines the thickness of the focus highlight. 
       
    • Trạng thái - Xác định nếu tiện ích sẽ phản hồi các chuyển động của chuột hoặc bàn phím. & nbsp; & nbsp; – defines the width of insertion character. 
       
    • Điểm nổi bật - Xác định độ dày của điểm nhấn tiêu điểm. & nbsp; & nbsp; – type of the border which can be SUNKEN, RAISED, GROOVE and RIDGE. 
       
    • chèn chiều - xác định độ rộng của ký tự chèn. & nbsp; & nbsp; – to make the widget vertically scrollable. 
       
    • Cứu trợ - Loại biên giới có thể bị chìm, nuôi, rãnh và sườn núi. & nbsp; & nbsp; – to make the widget horizontally scrollable. 
       

    yscrollCommand - để làm cho tiện ích có thể cuộn theo chiều dọc. & nbsp; & nbsp;
     

    • xscrollCommand - để làm cho tiện ích có thể cuộn theo chiều ngang. & nbsp; & nbsp;– To get the specified index. 
       
    • Một số phương pháp phổ biến & nbsp;– To insert a string at a specified index. 
       
    • INDEX (INDEX) - Để có được chỉ mục được chỉ định. & nbsp; & nbsp;– Checks if a string is visible or not at a given index. 
       
    • Chèn (chỉ mục) - Để chèn một chuỗi tại một chỉ mục được chỉ định. & nbsp; & nbsp; – to get characters within a given range. 
       
    • Xem (INDEX) - Kiểm tra xem một chuỗi có hiển thị hoặc không ở một chỉ mục nhất định. & nbsp; & nbsp; – deletes characters within specified range.

    GET (startIndex, endindex) - để có được các ký tự trong một phạm vi nhất định. & nbsp; & nbsp; 
     

    • Xóa (StartIndex, Endindex) - Xóa các ký tự trong phạm vi được chỉ định. – To delete a given tag. 
       
    • Phương thức xử lý thẻ & nbsp; & nbsp; – to tag the string in the specified range 
       
    • TAG_DELETE (TagName) - Để xóa một thẻ đã cho. & nbsp; & nbsp; – to remove a tag from specified range 
       

    TAG_ADD (TagName, StartIndex, Endindex) - Để gắn thẻ chuỗi trong phạm vi được chỉ định & nbsp; & nbsp; 
     

    • TAG_REMOVE (TagName, StartIndex, Endindex) - Để xóa thẻ khỏi phạm vi được chỉ định & nbsp; & nbsp;– to get all the marks in the given range. 
       
    • chỉ mục (đánh dấu) - để nhận chỉ mục của một nhãn hiệu. & nbsp; & nbsp;– to get index of a mark. 
       
    • mark_gravity () - để có được trọng lực của một dấu hiệu nhất định. & nbsp; – to get the gravity of a given mark.
       

    Ví dụ 1: & nbsp; & nbsp; 
     

    Python3

    print_msg_box('\n~ PYTHON ~\n')
    
    1
    print_msg_box('\n~ PYTHON ~\n')
    
    2

    print_msg_box('\n~ PYTHON ~\n')
    
    3
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n')
    
    5

    print_msg_box('\n~ PYTHON ~\n')
    
    6
    print_msg_box('\n~ PYTHON ~\n')
    
    7
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    print_msg_box('\n~ PYTHON ~\n')
    
    9
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    1
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    3
    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    4
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    6
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    8
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    0
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    2
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    4
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    6
    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    7
    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    8
    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    9
    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    0

    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    1
    print_msg_box('\n~ PYTHON ~\n')
    
    4

    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    3
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    5
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    7
    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    8

    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    9
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    5
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    3
    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    4

    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    5
    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    6
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    8

    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    9

    ╔════════════════════════════════════════╗
    ║                                        ║
    ║          ~ PYTHON ~                    ║
    ║                                        ║
    ╚════════════════════════════════════════╝
    
    0

    ╔════════════════════════════════════════╗
    ║                                        ║
    ║          ~ PYTHON ~                    ║
    ║                                        ║
    ╚════════════════════════════════════════╝
    
    1

    ╔════════════════════════════════════════╗
    ║                                        ║
    ║          ~ PYTHON ~                    ║
    ║                                        ║
    ╚════════════════════════════════════════╝
    
    2

    ╔════════════════════════════════════════╗
    ║                                        ║
    ║          ~ PYTHON ~                    ║
    ║                                        ║
    ╚════════════════════════════════════════╝
    
    3

    ╔════════════════════════════════════════╗
    ║                                        ║
    ║          ~ PYTHON ~                    ║
    ║                                        ║
    ╚════════════════════════════════════════╝
    
    4

    Output  
     

    Hướng dẫn python print text in a box - python in văn bản trong hộp

    Ví dụ 2: Lưu văn bản và hoạt động thực hiện & nbsp; Saving Text and performing operations
     

    Python3

    ╔════════════════════════════════════════╗
    ║                                        ║
    ║          ~ PYTHON ~                    ║
    ║                                        ║
    ╚════════════════════════════════════════╝
    
    5
    ╔════════════════════════════════════════╗
    ║                                        ║
    ║          ~ PYTHON ~                    ║
    ║                                        ║
    ╚════════════════════════════════════════╝
    
    6
    print_msg_box('\n~ PYTHON ~\n')
    
    1
    ╔════════════════════════════════════════╗
    ║                                        ║
    ║          ~ PYTHON ~                    ║
    ║                                        ║
    ╚════════════════════════════════════════╝
    
    8

    print_msg_box('\n~ PYTHON ~\n')
    
    3
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n')
    
    5

    print_msg_box('\n~ PYTHON ~\n')
    
    6
    msg = "And I thought to myself,\n" \
          "'a little fermented curd will do the trick',\n" \
          "so, I curtailed my Walpoling activites, sallied forth,\n" \
          "and infiltrated your place of purveyance to negotiate\n" \
          "the vending of some cheesy comestibles!"
    
    print_msg_box(msg=msg, indent=2, title='In a nutshell:')
    
    3
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    msg = "And I thought to myself,\n" \
          "'a little fermented curd will do the trick',\n" \
          "so, I curtailed my Walpoling activites, sallied forth,\n" \
          "and infiltrated your place of purveyance to negotiate\n" \
          "the vending of some cheesy comestibles!"
    
    print_msg_box(msg=msg, indent=2, title='In a nutshell:')
    
    5
    msg = "And I thought to myself,\n" \
          "'a little fermented curd will do the trick',\n" \
          "so, I curtailed my Walpoling activites, sallied forth,\n" \
          "and infiltrated your place of purveyance to negotiate\n" \
          "the vending of some cheesy comestibles!"
    
    print_msg_box(msg=msg, indent=2, title='In a nutshell:')
    
    6
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    print_msg_box('\n~ PYTHON ~\n')
    
    9
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    1
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    3
    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    4
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    6
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    8
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    0
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    2
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    ╔══════════════════════════════════════════════════════════╗
    ║  In a nutshell:                                          ║
    ║  --------------                                          ║
    ║  And I thought to myself,                                ║
    ║  'a little fermented curd will do the trick',            ║
    ║  so, I curtailed my Walpoling activites, sallied forth,  ║
    ║  and infiltrated your place of purveyance to negotiate   ║
    ║  the vending of some cheesy comestibles!                 ║
    ╚══════════════════════════════════════════════════════════╝
    
    0
    ╔══════════════════════════════════════════════════════════╗
    ║  In a nutshell:                                          ║
    ║  --------------                                          ║
    ║  And I thought to myself,                                ║
    ║  'a little fermented curd will do the trick',            ║
    ║  so, I curtailed my Walpoling activites, sallied forth,  ║
    ║  and infiltrated your place of purveyance to negotiate   ║
    ║  the vending of some cheesy comestibles!                 ║
    ╚══════════════════════════════════════════════════════════╝
    
    9
    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    6
    ╔══════════════════════════════════════════════════════════╗
    ║  In a nutshell:                                          ║
    ║  --------------                                          ║
    ║  And I thought to myself,                                ║
    ║  'a little fermented curd will do the trick',            ║
    ║  so, I curtailed my Walpoling activites, sallied forth,  ║
    ║  and infiltrated your place of purveyance to negotiate   ║
    ║  the vending of some cheesy comestibles!                 ║
    ╚══════════════════════════════════════════════════════════╝
    
    1
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    3
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    5
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    7
    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    8

    print_msg_box('\n~ PYTHON ~\n')
    
    01
    print_msg_box('\n~ PYTHON ~\n')
    
    02
    print_msg_box('\n~ PYTHON ~\n')
    
    03
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    ╔══════════════════════════════════════════════════════════╗
    ║  In a nutshell:                                          ║
    ║  --------------                                          ║
    ║  And I thought to myself,                                ║
    ║  'a little fermented curd will do the trick',            ║
    ║  so, I curtailed my Walpoling activites, sallied forth,  ║
    ║  and infiltrated your place of purveyance to negotiate   ║
    ║  the vending of some cheesy comestibles!                 ║
    ╚══════════════════════════════════════════════════════════╝
    
    0
    print_msg_box('\n~ PYTHON ~\n')
    
    06
    print_msg_box('\n~ PYTHON ~\n')
    
    07

    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    9
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔══════════════════════════════╗
    ║                              ║
    ║          ~ PYTHON ~          ║
    ║                              ║
    ╚══════════════════════════════╝
    
    5
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    3
    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    4

    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    5
    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    6
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    8

    Ví dụ 2: Lưu văn bản và hoạt động thực hiện & nbsp;

    ╔════════════════════════════════════════╗
    ║                                        ║
    ║          ~ PYTHON ~                    ║
    ║                                        ║
    ╚════════════════════════════════════════╝
    
    5
    ╔════════════════════════════════════════╗
    ║                                        ║
    ║          ~ PYTHON ~                    ║
    ║                                        ║
    ╚════════════════════════════════════════╝
    
    6
    print_msg_box('\n~ PYTHON ~\n')
    
    1
    ╔════════════════════════════════════════╗
    ║                                        ║
    ║          ~ PYTHON ~                    ║
    ║                                        ║
    ╚════════════════════════════════════════╝
    
    8

    msg = "And I thought to myself,\n" \
          "'a little fermented curd will do the trick',\n" \
          "so, I curtailed my Walpoling activites, sallied forth,\n" \
          "and infiltrated your place of purveyance to negotiate\n" \
          "the vending of some cheesy comestibles!"
    
    print_msg_box(msg=msg, indent=2, title='In a nutshell:')
    
    8
    msg = "And I thought to myself,\n" \
          "'a little fermented curd will do the trick',\n" \
          "so, I curtailed my Walpoling activites, sallied forth,\n" \
          "and infiltrated your place of purveyance to negotiate\n" \
          "the vending of some cheesy comestibles!"
    
    print_msg_box(msg=msg, indent=2, title='In a nutshell:')
    
    9

    ╔══════════════════════════════════════════════════════════╗
    ║  In a nutshell:                                          ║
    ║  --------------                                          ║
    ║  And I thought to myself,                                ║
    ║  'a little fermented curd will do the trick',            ║
    ║  so, I curtailed my Walpoling activites, sallied forth,  ║
    ║  and infiltrated your place of purveyance to negotiate   ║
    ║  the vending of some cheesy comestibles!                 ║
    ╚══════════════════════════════════════════════════════════╝
    
    0
    ╔══════════════════════════════════════════════════════════╗
    ║  In a nutshell:                                          ║
    ║  --------------                                          ║
    ║  And I thought to myself,                                ║
    ║  'a little fermented curd will do the trick',            ║
    ║  so, I curtailed my Walpoling activites, sallied forth,  ║
    ║  and infiltrated your place of purveyance to negotiate   ║
    ║  the vending of some cheesy comestibles!                 ║
    ╚══════════════════════════════════════════════════════════╝
    
    1
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔══════════════════════════════════════════════════════════╗
    ║  In a nutshell:                                          ║
    ║  --------------                                          ║
    ║  And I thought to myself,                                ║
    ║  'a little fermented curd will do the trick',            ║
    ║  so, I curtailed my Walpoling activites, sallied forth,  ║
    ║  and infiltrated your place of purveyance to negotiate   ║
    ║  the vending of some cheesy comestibles!                 ║
    ╚══════════════════════════════════════════════════════════╝
    
    3
    ╔══════════════════════════════════════════════════════════╗
    ║  In a nutshell:                                          ║
    ║  --------------                                          ║
    ║  And I thought to myself,                                ║
    ║  'a little fermented curd will do the trick',            ║
    ║  so, I curtailed my Walpoling activites, sallied forth,  ║
    ║  and infiltrated your place of purveyance to negotiate   ║
    ║  the vending of some cheesy comestibles!                 ║
    ╚══════════════════════════════════════════════════════════╝
    
    4
    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    8
    ╔══════════════════════════════════════════════════════════╗
    ║  In a nutshell:                                          ║
    ║  --------------                                          ║
    ║  And I thought to myself,                                ║
    ║  'a little fermented curd will do the trick',            ║
    ║  so, I curtailed my Walpoling activites, sallied forth,  ║
    ║  and infiltrated your place of purveyance to negotiate   ║
    ║  the vending of some cheesy comestibles!                 ║
    ╚══════════════════════════════════════════════════════════╝
    
    6
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    ╔══════════════════════════════════════════════════════════╗
    ║  In a nutshell:                                          ║
    ║  --------------                                          ║
    ║  And I thought to myself,                                ║
    ║  'a little fermented curd will do the trick',            ║
    ║  so, I curtailed my Walpoling activites, sallied forth,  ║
    ║  and infiltrated your place of purveyance to negotiate   ║
    ║  the vending of some cheesy comestibles!                 ║
    ╚══════════════════════════════════════════════════════════╝
    
    0
    # Import the required library
    from tkinter import *
    from tkinter import ttk
    
    # Create an instance of tkinter frame
    win=Tk()
    
    # Set the geometry
    win.geometry("700x350")
    
    def get_input():
       label.config(text=""+text.get(1.0, "end-1c"))
    
    # Add a text widget
    text=Text(win, width=80, height=15)
    text.insert(END, "")
    text.pack()
    
    # Create a button to get the text input
    b=ttk.Button(win, text="Print", command=get_input)
    b.pack()
    
    # Create a Label widget
    label=Label(win, text="", font=('Calibri 15'))
    label.pack()
    
    win.mainloop()
    4
    print_msg_box('\n~ PYTHON ~\n', indent=10)
    
    6
    ╔══════════════════════════════════════════════════════════╗
    ║  In a nutshell:                                          ║
    ║  --------------                                          ║
    ║  And I thought to myself,                                ║
    ║  'a little fermented curd will do the trick',            ║
    ║  so, I curtailed my Walpoling activites, sallied forth,  ║
    ║  and infiltrated your place of purveyance to negotiate   ║
    ║  the vending of some cheesy comestibles!                 ║
    ╚══════════════════════════════════════════════════════════╝
    
    1
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    # Import the required library
    from tkinter import *
    from tkinter import ttk
    
    # Create an instance of tkinter frame
    win=Tk()
    
    # Set the geometry
    win.geometry("700x350")
    
    def get_input():
       label.config(text=""+text.get(1.0, "end-1c"))
    
    # Add a text widget
    text=Text(win, width=80, height=15)
    text.insert(END, "")
    text.pack()
    
    # Create a button to get the text input
    b=ttk.Button(win, text="Print", command=get_input)
    b.pack()
    
    # Create a Label widget
    label=Label(win, text="", font=('Calibri 15'))
    label.pack()
    
    win.mainloop()
    9
    print_msg_box('\n~ PYTHON ~\n')
    
    00

    print_msg_box('\n~ PYTHON ~\n')
    
    01______102211011018

    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    8
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n')
    
    14
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n')
    
    16
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    print_msg_box('\n~ PYTHON ~\n')
    
    18
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    ╔════════════╗
    ║            ║
    ║ ~ PYTHON ~ ║
    ║            ║
    ╚════════════╝
    
    1
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n')
    
    222
    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    4

    print_msg_box('\n~ PYTHON ~\n')
    
    24
    print_msg_box('\n~ PYTHON ~\n')
    
    25
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n')
    
    27
    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    4

    print_msg_box('\n~ PYTHON ~\n')
    
    24
    print_msg_box('\n~ PYTHON ~\n')
    
    30
    print_msg_box('\n~ PYTHON ~\n')
    
    4
    print_msg_box('\n~ PYTHON ~\n')
    
    32
    print_msg_box('\n~ PYTHON ~\n')
    
    8

    print_msg_box('\n~ PYTHON ~\n', indent=10, width=20)
    
    9

    print_msg_box('\n~ PYTHON ~\n')
    
    72

    print_msg_box('\n~ PYTHON ~\n')
    
    73

    print_msg_box('\n~ PYTHON ~\n')
    
    74

    print_msg_box('\n~ PYTHON ~\n')
    
    75

    Output   
     

    Hướng dẫn python print text in a box - python in văn bản trong hộp


    Làm thế nào để bạn in một hộp văn bản bằng Python?

    Chà, trước tiên, bạn sẽ phải tạo hộp văn bản trong Phương thức init => self.textbox = tk.text (self). Sau đó, bạn chỉ cần chèn văn bản bạn muốn vào nó trong phương thức on_button => self.textbox.insert (tk.end, the_text) - Julien Spronck. Ngày 21 tháng 3 năm 2015 lúc 7:17 ..
    @Julienspronck Cảm ơn bạn. - Nó ADSD. Ngày 21 tháng 3 năm 2015 lúc 7:33 ..

    %% trong Python là gì?

    Biểu tượng % trong Python được gọi là toán tử modulo. Nó trả về phần còn lại của việc chia toán hạng tay trái cho toán hạng bên phải.Modulo Operator. It returns the remainder of dividing the left hand operand by right hand operand.

    Tôi có thể in \ n trong python không?

    Tóm tắt, ký tự dòng mới trong Python là \ n.Nó được sử dụng để chỉ ra sự kết thúc của một dòng văn bản.Bạn có thể in các chuỗi mà không cần thêm một dòng mới có kết thúc =, đó là ký tự sẽ được sử dụng để tách các dòng.You can print strings without adding a new line with end = , which is the character that will be used to separate the lines.

    Làm thế nào để bạn in một biến và một chuỗi?

    Sử dụng chuỗi F để in một biến với một chuỗi trong câu lệnh in (), thêm f trước một chuỗi chữ và chèn {var} trong chuỗi chữ để in theo chữ theo chữ cái với biến var được chèn tại vị trí được chỉ định. Within a print() statement, add f before a string literal and insert {var} within the string literal to print the string literal with the variable var inserted at the specified location.