[英]new window in python 3 and tkinter by clicking on button
这是我现在制作的程序,但是我有问题...当我单击button1然后打开新窗口时,我该如何制作
import sys
from tkinter import *
import tkinter as tk
def mhello1():
mlabel = Label(mGui, text='A1').pack()
def mhello2():
mlabel = Label(mGui, text='A2').pack()
def mhello3():
mlabel = Label(mGui, text='A3').pack()
def mhello4():
mlabel
return
def mAbout():
messagebox.showinfo(title="About",message="program")
return
def mQuit():
mExit = messagebox.askyesno(title="Quit",message="y/n")
if mExit > 0:
mGui.destroy()
return
mGui = Tk()
mGui.geometry('450x450+200+200')
mGui.title('program')
mGui.configure(bg='gray')
mlabel = Label(text='option:',fg='red',bg = 'blue').pack()
mbutton1 = Button(mGui,text ='Button1',command = mhello1, height=5, width=20).pack()
mbutton2 = Button(mGui,text ='Button2',command = mhello2, height=5, width=20).pack()
mbutton3 = Button(mGui,text ='Button3',command = mhello3, height=5, width=20).pack()
mbutton4 = Button(mGui,text ='Button4',command = mhello4, height=5, width=20).pack()
mlabel2 = Label(text='activity:',fg='red',bg = 'blue').pack()
menubar=Menu(mGui)
filemenu = Menu(menubar, tearoff = 0)
filemenu.add_command(label="qwer")
filemenu.add_command(label="quit",command = mQuit)
menubar.add_cascade(label="more options",menu=filemenu)
helpmenu = Menu(menubar, tearoff = 0)
helpmenu.add_command(label="Help Docs")
helpmenu.add_command(label="About", command = mAbout)
menubar.add_cascade(label="help",menu=helpmenu)
mGui.config(menu=menubar)
mGui.mainloop()
我尝试了该程序,但是它不起作用: Python 3和tkinter通过单击按钮打开新窗口
有没有一种方法我不使用tkinter顶级?
Tnx很多:)
由于您只应创建一个根窗口,因此必须使用“ 顶层”打开一个新的根窗口。
def mhello1():
toplevel = Toplevel()
toplevel.title('Another window')
toplevel.focus_set()
如果您想使用消息框,请在下面使用这些行
from tkinter import *
from tkinter import messagebox
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.