[英]How can I get the name's Entry for tkinter.messagebox in this code?
How can I get the name's Entry for tkinter.messagebox in this code?如何在此代码中获取 tkinter.messagebox 的名称条目? The def.OnClick doesn't see myInput variable.
def.OnClick 没有看到 myInput 变量。 Help me please, I'm newbie at Python
请帮助我,我是 Python 的新手
import tkinter as tk
from tkinter import *
from tkinter import messagebox
from tkinter.font import names
# window settings
win = Tk()
win.geometry("250x350")
win.resizable(0,0)
win.title("Test app")
# def and other
Input1 = StringVar()
def show1():
myLabel3 = Label(win, text="I love Python :)", font=("Montserrat", 18), highlightbackground='darkred', highlightthickness=3)
myLabel3.place(x=30, y=130)
myLabel4 = Label(win, text="Now, enter your name!", font=("Montserrat", 15))
myLabel4.place(x=5, y=190)
myInput = Entry(win, font=("Montserrat", 17), textvariable=Input1, width=100, justify=LEFT)
myInput.place(x=0, y=240)
Button2 = Button(win, text="Apply", font=("Montserrat"), command=onClick)
Button2.place(x=90, y=290)
def onClick():
tk.messagebox.showinfo("Your name", f"Your name - {myInput}")
# widgets
myLabel1 = Label(win, text="Hello World!", font=("Montserrat", 20))
myLabel2 = Label(win, text="Click this button!", font=("Montserrat", 16))
Button1 = Button(win, text="Click me pls!", font=("Montserrat"), command=show1)
# widgets settings
myLabel1.place(x=35)
myLabel2.place(x=26, y=40)
Button1.place(x=62, y=83)
win.mainloop()
replace {myInput} with {Input1.get()}用 {Input1.get()} 替换 {myInput}
# def and other
Input1 = StringVar()
def show1():
myInput = Entry(win, font=("Montserrat", 17), textvariable=Input1, width=100, justify=LEFT)
myInput.place(x=0, y=240)
Button2 = Button(win, text="Apply", font=("Montserrat"), command=onClick)
Button2.place(x=90, y=290)
def onClick():
tk.messagebox.showinfo("Your name", f"Your name - {Input1.get()}")
win.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.