Reputation: 573
I am trying to write a script that will ask a word in English and then show its meaning. I am able to ask the question but the answer window doesn't show up. Code I wrote so far as below. In second window, it starts like a new page. How can I modify it? Now, it shows the label but buttons doesn't seem.
from tkinter import *
class Application(Frame):
def __init__(self, master):
"""Initialize the Frame"""
Frame.__init__(self, master)
self.grid()
self.button_clicks = 0 # count the number of button clicks
self.create_widgets()
def root_close(self):
global root
root.destroy()
self.button_clicky()
def create_widgets(self):
"""Button displays number of clicks"""
if clicker % 2 == 0:
self.soru = Label(self, text="Kelime: " + kelime)
self.soru.grid(row=0, column=0, columnspan=2, sticky=W)
self.btn_submit = Button(self, text="Submit", command=self.root_close)
self.btn_submit.grid(row=3, column=1, sticky=W)
else:
self.cevap = Label(self, text="Kelimenin türkçe anlamları:\n" + anlam)
self.cevap.grid(row=0, column=0, columnspan=2, sticky=W)
self.btn_okay = Button(self, text="Bildim", command=self.dogru)
self.btn_submit.grid(row=3, column=0, sticky=W)
self.btn_okay = Button(self, text="Bilemedim", command=self.yanlis)
self.btn_submit.grid(row=3, column=2, sticky=W)
def button_clicky(self):
global clicker
clicker += 1
def dogru(self):
#will do stuff
self.root_close()
def yanlis(self):
self.root_close()
clicker = 0
kelime = "apple"
anlam = "elma"
root = Tk()
root.title("Ask word")
root.geometry("200x85")
app = Application(root)
root.mainloop()
Upvotes: 1
Views: 1888
Reputation: 36
So what I get from your question is that you have the first window with the Kelime question, and you want to open up another window with the else clause in your create_widgets()
function once you click the submit button. The problem here is that when you are running root_close()
, you're essentially terminating the whole program (the program runs because the root is on a loop created by root.mainLoop()
). If you want to open one window when you close the other, check out Closing current window when opening another window
.
Upvotes: 2