Python 这就是你的意思吗??它不起作用:(@progmaticoi这就是你的意思吗?)它不起作用:(从tkinter导入*def get(s):print(s.get())def newwin():win=Toplevel()s=StringVar()button

Python 这就是你的意思吗??它不起作用:(@progmaticoi这就是你的意思吗?)它不起作用:(从tkinter导入*def get(s):print(s.get())def newwin():win=Toplevel()s=StringVar()button,python,python-3.x,tkinter,tkinter-entry,Python,Python 3.x,Tkinter,Tkinter Entry,这就是你的意思吗??它不起作用:(@progmaticoi这就是你的意思吗?)它不起作用:(从tkinter导入*def get(s):print(s.get())def newwin():win=Toplevel()s=StringVar()button=button(win,text='click',command=lambda:get(s)).grid(row=1)ent=Entry(win,textvariable=s)。grid()win.grab\u set()root=Tk()bu


这就是你的意思吗??它不起作用:(@progmaticoi这就是你的意思吗?)它不起作用:(从tkinter导入*def get(s):print(s.get())def newwin():win=Toplevel()s=StringVar()button=button(win,text='click',command=lambda:get(s)).grid(row=1)ent=Entry(win,textvariable=s)。grid()win.grab\u set()root=Tk()but=button(root,text='New',command=newwin).grid()刚刚在上面的答案中添加了一个解释。我如何限制选择旧窗口?在关闭新窗口(顶级)之前,我应该无法选择旧窗口…我如何做?添加
win.grab_set()
作为
newwin()中的最后一条指令
method。新窗口将捕获所有事件。从tkinter import*def get(s):print(s.get())def newwin():win=Toplevel()s=StringVar()button=button(win,text='click',command=lambda:get(s)).grid(row=1)ent=Entry(win,textvariable=s)。grid()win.grab_set()root=Tk()button=button(root,text='new',','command=newwin).grid()这是你的意思吗?它不起作用:(@progmaticoi这是你的意思吗?)它不起作用:(从tkinter导入*def get(s):print(s.get())def newwin():win=Toplevel()s=StringVar()button=button(win,text='click',command=lambda:get(s)).grid(row=1)ent=Entry(win,textvariable=s).grid()win.grab_set()root=Tk()但=Button(root,text='New',command=newwin).grid()
from tkinter import *
def get(s):
        print(s.get())
win=Tk()
s=StringVar()
button=Button(win,text='click',command=lambda:get(s)).grid(row=1)
ent=Entry(win,textvariable=s).grid()
from tkinter import *
def get(s):
        print(s.get())
def newwin():
    win=Tk()
    s=StringVar()
    button=Button(win,text='click',command=lambda:get(s)).grid(row=1)
    ent=Entry(win,textvariable=s).grid()
root=Tk()
but=Button(root,text='New',command=newwin).grid()
def newwin():
    win=Tk()
...
def newwin():
    win=Toplevel(root)
    ...
 def newwin():
    win=Tk()
    s=StringVar()
    ...
def newwin():
    win=Tk()
    s=StringVar(win)
    ...
def newwin():
    win=Tk(Toplevel(root))
    s=StringVar()
    button=Button(win,text='click',command=lambda:get(s)).grid(row=1)
    ent=Entry(win,textvariable=s).grid()
    win.grab_set() # win will catch all events, until you close it
                   # so user cannot interact with root window widgets
    # root.widthdraw() # alternative approach hides root window
                       # until Toplevel closes


root=Tk()
but=Button(root,text='New',command=newwin).grid()
import tkinter as tk
from tkinter import Tk, ttk

class MyWindow(tk.Toplevel):
    def __init__(self, parent, *kw):
        super().__init__(parent, *kw)
        self.title('New Toplevel Window')
        self.myvar = tk.StringVar()
        self.button = ttk.Button(self, text='Print myvar',
            command=self.print_myvar)
        self.entry = ttk.Entry(self, textvariable=self.myvar)
        self.button.pack(pady=5)
        self.entry.pack(padx=50, pady=5)
        self.grab_set() # capture all the events
        self.bind('<FocusOut>', self.dont_let_focus_go) # cannot focus root


    def print_myvar(self):
        print(self.myvar.get())

    def dont_let_focus_go(self, event=None):
        self.focus_force()

def new_window():
    MyWindow(root)

root = Tk()
root.title('My Application Root Window')

button = ttk.Button(root, text='New Window', command=new_window)
button.pack(padx=50, pady=5)

root.mainloop()