2017-09-30 10 views
1

がどのように私はボタンのいずれかをクリックしたときに、これはそれが新しいウィンドウが表示されますか、ウィンドウ内のすべてを削除し、質問と回答でそれを置き換えるになるだろう、新しいウィンドウを作成する:クイズPythonは

import tkinter 
from tkinter import* 
from tkinter import ttk 
from tkinter import messagebox 

def open_msg_box(): 
    messagebox.showinfo(
     "Event Triggered", 
     "Button Clicked" 
    ) 

root= Tk() 
root.geometry("900x150+200+250") 
root.configure(background = "Light blue") 

frame = Frame(root) 
style = ttk.Style() 

style.configure("TButton", 
       foreground="midnight blue", 
       font="Times 20 bold italic", 
       padding=20) 
style.configure("TLabel", 
       foreground="midnight blue", 
       font="Times 20 bold italic", 
       padding=20) 

question = ttk.Label(root, text="Choose a Topic").pack(side=TOP) 
theButton= ttk.Button(root, text="History", 
command=open_msg_box).pack(side=LEFT) 
theButton2= ttk.Button(root, text="Music", 
command=open_msg_box).pack(side=RIGHT) 
theButton3= ttk.Button(root, text="Computer Science", 
command=open_msg_box).pack() 


frame.pack() 

root.mainloop() 

答えて

0

ができこれを行うための多くの方法であり、そこにあります。あなたが望むかもしれないこれらの2つの答えを尋ねるように、最初のものは最初のものを削除せずに次のウィンドウを開き、2番目の方法は新しいものを開くときに最後のウィンドウを破壊する方法を示します。

import tkinter 
from tkinter import* 
from tkinter import ttk 
class way1: 
    def __init__(self): 
     root= Tk() 
     self.root=root 
     root.geometry("900x150+200+250") 
     root.configure(background = "Light blue") 

     frame = Frame(root) 
     style = ttk.Style() 

     style.configure("TButton",foreground="midnight blue",font="Times 20 bold italic",padding=20) 
     style.configure("TLabel",foreground="midnight blue",font="Times 20 bold italic",padding=20) 

     question = ttk.Label(root, text="Choose a Topic").pack(side=TOP) 
     theButton= ttk.Button(root, text="History", command=self.histroy_quetsion).pack(side=LEFT) 
     theButton2= ttk.Button(root, text="Music",command=self.Music_quetsion).pack(side=RIGHT) 
     theButton3= ttk.Button(root, text="Computer Science", command=self.Computer_quetsion).pack() 


     frame.pack() 

     root.mainloop() 
    def histroy_quetsion(self): 
     histroy=Toplevel(self.root) 
     question = ttk.Label(histroy, text="These is the histroy quetsion and answer page").pack(side=TOP) 
    def Music_quetsion(self): 
     Music=Toplevel(self.root) 
     question = ttk.Label(Music, text="These is music quetsion and answer page").pack(side=TOP) 
    def Computer_quetsion(self): 
     Computer=Toplevel(self.root) 
     question = ttk.Label(Computer, text="These is the coumputer science quetsion and answer page").pack(side=TOP) 
way1() 

class way2: 
    def __init__(self): 
     root= Tk() 
     self.root=root 
     root.geometry("900x150+200+250") 
     root.configure(background = "Light blue") 

     frame = Frame(root) 
     style = ttk.Style() 

     style.configure("TButton",foreground="midnight blue",font="Times 20 bold italic",padding=20) 
     style.configure("TLabel",foreground="midnight blue",font="Times 20 bold italic",padding=20) 

     question = ttk.Label(root, text="Choose a Topic").pack(side=TOP) 
     theButton= ttk.Button(root, text="History", command=self.histroy_quetsion).pack(side=LEFT) 
     theButton2= ttk.Button(root, text="Music",command=self.Music_quetsion).pack(side=RIGHT) 
     theButton3= ttk.Button(root, text="Computer Science", command=self.Computer_quetsion).pack() 


     frame.pack() 

     root.mainloop() 
    def histroy_quetsion(self): 
     self.root.destroy() 
     root=Tk() 
     question = ttk.Label(root, text="These is the histroy quetsion and answer page").pack(side=TOP) 
    def Music_quetsion(self): 
     self.root.destroy() 
     root=Tk() 
     question = ttk.Label(root, text="These is music quetsion and answer page").pack(side=TOP) 
    def Computer_quetsion(self): 
     self.root.destroy() 
     root=Tk() 
     question = ttk.Label(root, text="These is the coumputer science quetsion and answer page").pack(side=TOP) 
way2() 
+0

あなたはもっと服装をしたいと思っていますし、何か質問がありましたら、私はそれらに答えることができるほど努力します – Hilea