Iceman
Iceman

Reputation: 45

How to open a new window on textbox click using tkinter

I have a program where upon pressing login button opens a new screen. On this screen is 3 text boxes which upon pressing I would like to open a new screen (this new screen will eventually become a numpad or keyboard used to enter data).

However i am struggling to get the new window to open upon clicking the textbox.

In essence Main screen open upon load. login widget opens when login button is pressed. upon clicking any text box calibration1, calibration2 or calibration3, this should open widget new_window.

new_window will eventually be turned into a keyboard or numpad.

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 Opened 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()

any Help would be greatly appreciated

Upvotes: 1

Views: 1096

Answers (1)

hussic
hussic

Reputation: 1920

Your code:

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

assign None to calibration1_entry. It should be:

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

Instead of print(e) you must use your function.

Upvotes: 1

Related Questions