简体   繁体   English

如何在此代码中获取 tkinter.messagebox 的名称条目?

[英]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.

相关问题 tkinter.messagebox 之后如何进入 - How after tkinter.messagebox then entry tkinter.messagebox中的“ For”循环? - “For” loops within a tkinter.messagebox? 导入 tkinter 的“messagebox”模块时,“import tkinter.messagebox”语法是否不起作用? - When importing tkinter's “messagebox” module, does the “import tkinter.messagebox” syntax not work? showinfo 和 showwarning 出现在 tkinter.messagebox 的背景中 - showinfo and showwarning appearing in the background in tkinter.messagebox 如何在 tkinter 中重复获取新行的值? 下面的代码仅获取 tkinter 条目小部件中的最后一行 - How can I get new row's value repeatedly in tkinter? The code below gets only the last row in tkinter entry widget 为什么导入tkinter之后,我需要导入tkinter.messagebox但不需要导入tkinter.Tk()? - Why do I need to import tkinter.messagebox but don't need to import tkinter.Tk() after importing tkinter? Python - tkinter.messagebox 在 macOS 中看不到标题和显示错误图标 - Python - tkinter.messagebox cannot see title and showerror icon in macOS “if”语句用于显示错误 tkinter.messagebox 不起作用 - "if" statement used to display an error tkinter.messagebox is not working 我可以在自定义的Tkinter Toplevel()窗口上获得消息框的图标=“ warning”噪音吗? - Can I get messagebox's icon=“warning” noise on a custom Tkinter Toplevel() window? 如何使用 tkinter 条目的名称保存 csv 文件? - How can I save a csv file with the name of a tkinter entry?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM