簡體   English   中英

如何在文本框上打開一個新的 window 單擊使用 tkinter

[英]How to open a new window on textbox click using tkinter

我有一個程序,按下登錄按鈕會打開一個新屏幕。 此屏幕上有 3 個文本框,按下后我想打開一個新屏幕(這個新屏幕最終將成為用於輸入數據的小鍵盤或鍵盤)。

但是,我正在努力讓新的 window 在單擊文本框時打開。

本質上主屏幕在加載時打開。 按下登錄按鈕時登錄小部件打開。 單擊任何文本框 calibration1、calibration2 或 calibration3 后,應該會打開小部件 new_window。

new_window 最終會變成鍵盤或小鍵盤。

from tkinter import *
import os
import time
from tkinter import simpledialog

def new_window():
    global screen6
    screen6 = Toplevel(screen)
    screen6.title("Sucess")
    screen6.geometry("150x100")
    Label(screen4, text = "New Window Openned Successfully").pack()

def login():
    global screen2
    screen2 = Toplevel(screen)
    screen2.title("Login")
    screen2.geometry("530x290")
    Label(screen2, text = "please enter details below to login").pack()
    Label(screen2, text = "").pack()
   
    calibration1 = StringVar()
    calibration2 = StringVar()
    calibration3 = StringVar()
   
    global calibration1_entry
    global calibration2_entry
    global calibration3_entry
   
    calibration1_entry= Entry(screen2, textvariable = calibration1).place(x=350, y=70)
    calibration2_entry = Entry(screen2, textvariable = calibration2).place(x=350, y=120)
    calibration3_entry = Entry(screen2, textvariable = calibration3).place(x=350, y=170)

def main_screen():
    global screen
    screen = Tk()
    screen.geometry("530x290")
    screen.title("Remote Monitoring Site 1")
    Label(text = "Remote Monitoring Site 1", bg = "grey", width = "300", height = "2", font = ("Calibri", 13)).pack()
    Label(text = "").pack()
    Button(text = "Login", width = "30", height = "2", command = login).pack()
    Label(text = "").pack()
   
    screen.mainloop()

main_screen()

任何幫助將不勝感激

你的代碼:

  calibration1_entry = Entry(screen2, textvariable=calibration1).place(x=350, y=70)

None分配給calibration1_entry 它應該是:

calibration1_entry = Entry(screen2, textvariable=calibration1)
calibration1_entry.place(x=350, y=70) # return None
calibration1_entry.bind('<Button-1>', lambda e: print(e))

您必須使用 function 而不是print(e)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM