Dec-07-2020, 08:45 PM
import tkinter as tk
root = tk.Tk()
myfont = "helvitica 25"
mybg = "light sky blue"
myheight = 4
mywidth = 60
myheight2 = 6
mywidth2 = 20
myheight3 = 3
mywidth3 = 20
labcol = "spring green"
anscol = "yellow"
otherbutcol = "light sky blue"
mypadx =0
mypady=0
class Main:
def __init__(self, root):
self.root = root
root.geometry('1200x1200')
self.First()
def First(self):
self.firstframe = tk.Frame(self.root)
self.firstframe.grid(row=0, column=0)
self.firstlabel = tk.Label(self.firstframe, text="firstlabel ", bg=labcol, font=myfont, relief="groove")
self.firstlabel .config(height=myheight, width=mywidth)
self.firstlabel .grid(row=1, column=1, sticky=tk.W)
self.firstcommandbutton = tk.Button(self.firstframe, text="firstcommandbutton", bg=otherbutcol, font=myfont,
relief="groove", command=self.Second)
self.firstcommandbutton.config(height=myheight, width=mywidth)
self.firstcommandbutton.grid(row=2, column=1, sticky=tk.W)
self.quitbn = tk.Button(self.firstframe, text="Quit", font=myfont, bg="red", relief="groove",
command=self.firstframe.quit)
self.quitbn.config(height=myheight, width=mywidth)
self.quitbn.grid(row=3, column=1, sticky=tk.W)
def Second (self):
print("It worked")
m = Main(root)
root.mainloop()
import tkinter as tk
root = tk.Tk()
myfont = "helvitica 25"
mybg = "light sky blue"
myheight = 4
mywidth = 60
myheight2 = 6
mywidth2 = 20
myheight3 = 3
mywidth3 = 20
labcol = "spring green"
anscol = "yellow"
otherbutcol = "light sky blue"
mypadx =0
mypady=0
class Main:
def __init__(self, root):
self.root = root
root.geometry('1200x1200')
self.First()
def First(self):
self.firstframe = tk.Frame(self.root)
self.firstframe.grid(row=0, column=0)
self.firstlabel = tk.Label(self.firstframe, text="firstlabel ", bg=labcol, font=myfont, relief="groove")
self.firstlabel .config(height=myheight, width=mywidth)
self.firstlabel .grid(row=1, column=1, sticky=tk.W)
self.firstcommandbutton = tk.Button(self.firstframe, text="firstcommandbutton", bg = otherbutcol, font=myfont,
relief="groove", command=self.Second)
self.firstcommandbutton.config(height=myheight, width=mywidth)
self.firstcommandbutton.grid(row=2, column=1, sticky=tk.W)
self.quitbn = tk.Button(self.firstframe, text="Quit", font=myfont, bg="red", relief="groove",
command=self.firstframe.quit)
self.quitbn.config(height=myheight, width=mywidth)
self.quitbn.grid(row=3, column=1, sticky=tk.W)
def Second (self):
print("It worked")
m = Main(root)
root.mainloop()This code creates a command button called "firstcommandbutton". This button calls the method "Second". Can I create code in Second, that gives me the name of the firstcommandbutton, and reads it into a variable.? If that is not possible can I get the text of the firstcommandbutton?
