>

AAAAAAA 텍스트를 한 창에 인쇄하고 BBBBBBB를 다른 창에 인쇄하고 싶지만 캔버스를 사용하여 어떻게합니까?

from tkinter import*
root = Tk()
canvas = Canvas(root)
canvas.pack(fill=BOTH, expand=1) # Stretch canvas to root window size.
root.wm_geometry("794x370")
root.title('Map')
def toplevel():
    top = Toplevel()
    top.title('Optimized Map')
    top.wm_geometry("794x370")
    optimized_canvas = Canvas(top)
    optimized_canvas.pack(fill=BOTH, expand=1)

toplevel()
l0 = Label(canvas, text="AAAAAAA", font= "calibri 32 bold",bg="white" )
canvas.create_window(0,70, window=l0, anchor=NW)
l1 = Label(canvas, text="BBBBBBB", font= "calibri 32 bold",bg="white" )
canvas.create_window(0,70, window=l1, anchor=NW)
root.mainloop()

  • 답변 # 1

    optimized_canvas 사용  두 번째 라벨 포함

    import tkinter as tk
    # ---
    root = tk.Tk()
    canvas = tk.Canvas(root)
    canvas.pack(fill='both', expand=True)
    l0 = tk.Label(canvas, text="AAAAAAA")
    canvas.create_window(0, 70, window=l0, anchor='nw')
    # ---
    top = tk.Toplevel(root)
    optimized_canvas = tk.Canvas(top)
    optimized_canvas.pack(fill='both', expand=True)
    l1 = tk.Label(optimized_canvas, text="BBBBBBB")
    optimized_canvas.create_window(0, 70, window=l1, anchor='nw')
    # ---
    root.mainloop()
    
    

    <시간>

    함수로 캔버스를 생성하면 캔버스가 로컬 변수에 할당되고이를 사용하려면 외부/전역 변수에 할당해야합니다.

    import tkinter as tk
    # --- functions ---
    def create_top(root):
        top = tk.Toplevel(root)
        local_canvas = tk.Canvas(top)
        local_canvas.pack(fill='both', expand=True)
        return local_canvas
    # ---
    root = tk.Tk()
    canvas = tk.Canvas(root)
    canvas.pack(fill='both', expand=True)
    l0 = tk.Label(canvas, text="AAAAAAA")
    canvas.create_window(0, 70, window=l0, anchor='nw')
    # ---
    optimized_canvas = create_top(root)
    l1 = tk.Label(optimized_canvas, text="BBBBBBB")
    optimized_canvas.create_window(0, 70, window=l1, anchor='nw')
    # ---
    root.mainloop()
    
    

  • 이전 kafka 주제의 파티션 수보다 많은 실행 프로그램을 스파크 작업에 할당하면 어떻게됩니까?
  • 다음 javascript - dojo - 모든 xhr/ajax 호출은 동기식이며 다른 호출을 차단합니다