Hello all,
A script should open an application with two buttons visible. When Hello button is pressed a new button is gridded into the row number 1 and Hello button to be deactivated. When this new button is pressed it should delete itself off the grid and reactivate hello button but it does not do it. Any ideas?
Please check the video to see it in action. - from tkinter import *
-
-
class Application(Frame):
-
def __init__(self, master=None):
-
self.master = master
-
self.master.geometry('300x100+10+10')
-
Frame.__init__(self, master)
-
self.pack()
-
self.createWidgets()
-
-
def new_button(self):
-
print("enable_b")
-
self.hi_there.config(state=ACTIVE)
-
self.new_button.grid_remove()
-
-
def say_hi(self):
-
print("hi there, everyone!")
-
self.new_button = Button(self)
-
self.new_button["text"] = "New BTN"
-
self.new_button.grid(row=1,column=0)
-
self.hi_there.config(state=DISABLED, command=self.new_button)
-
-
def createWidgets(self):
-
self.QUIT = Button(self)
-
self.QUIT.config(text="QUIT",fg="red",command=self.quit)
-
self.QUIT.grid(row=0,column=1)
-
self.hi_there = Button(self)
-
self.hi_there["text"] = "Hello",
-
self.hi_there["command"] = self.say_hi
-
self.hi_there.grid(row=0,column=0)
-
-
def quit(self):
-
self.master.destroy()
-
-
def testit():
-
root = Tk()
-
app = Application(master=root)
-
app.mainloop()
-
-
if __name__ == '__main__':
-
testit()
1 1377
No one is going to click an unknown (video) link from a public forum. You can use 2 functions, one for each button, or you can use a variable and one function, per the following code. - from tkinter import *
-
-
class Application():
-
def __init__(self, master=None):
-
self.master = master
-
self.master.geometry('300x100+10+10')
-
self.buttons_state=True ## True= hi_there, False=new_buttpn
-
self.createWidgets()
-
-
def change_buttons(self):
-
if self.buttons_state:
-
self.hi_there.config(state=ACTIVE)
-
self.new_button.grid_remove()
-
else:
-
self.hi_there.config(state=DISABLED)
-
self.new_button.grid(row=1,column=0)
-
-
self.buttons_state = not self.buttons_state
-
-
def createWidgets(self):
-
self.QUIT = Button(self.master)
-
self.QUIT.config(text="QUIT",fg="red",
-
command=self.master.quit)
-
self.QUIT.grid(row=9,column=0)
-
-
self.hi_there = Button(self.master, state=DISABLED)
-
self.hi_there["text"] = "Hello"
-
self.hi_there["command"] = self.change_buttons
-
self.hi_there.grid(row=0,column=0)
-
-
self.new_button = Button(self.master, command=self.change_buttons)
-
self.new_button["text"] = "New BTN"
-
self.new_button.grid(row=1,column=0)
-
self.master.rowconfigure(1, weight=1, minsize=20)
-
-
if __name__ == '__main__':
-
root = Tk()
-
app = Application(master=root)
-
root.mainloop()
Sign in to post your reply or Sign up for a free account.
Similar topics
by: yootzee |
last post by:
Greetings all,
I'm having a problem with scrolling vertically in a newly created
browser
window. The vertical scrolling is to reach some anchor point within
the new
browser window.
I'm...
|
by: pmatos |
last post by:
Hi all,
Sometimes I have a function which creates an object and returns it.
Some are sets, other vectors but that's not very important. In these
cases I do something like this:
vector<int> *...
|
by: Earl Teigrob |
last post by:
I am having a problem where the bitmap image that I just created and saved
to disk can not be found but the code in another area of the program. When I
reattempt to access the same image, it...
|
by: mcwooq |
last post by:
Hi,
I just installed the VS.Studio 2005 Team Edition for Developper and
encountered
severe problems with debugging ASP.NET 2.0 projects. Even newly empty
created ASP 2.0 projects can't debug...
|
by: mcmwhite |
last post by:
Hi,
Does anyone know how I can open a newly-created HTML page
in a new window, using ASP.NET?
Eg. I have an ASP.NET page which creates some new HTML, based
on what the user has entered into a...
|
by: sankaba |
last post by:
Hi,
I have created a new user for a database that i hav created in DB2, by expanding the database tree diagram in control center right upto DB users folder, and then right clicking it and...
|
by: Craig Taylor |
last post by:
I have a javascript function as follows: (without the prefixed *'s)
function addTest( )
{
ePop = document.getElementById( "popups" );
eWin2 = document.createElement( "div");...
|
by: Chris B |
last post by:
Howdy,
When the AddNew button is clicked on the BindingNavigator, a new row is made in the datagrid and the row selector moves to that newly created row, what is the method that moves the selector...
|
by: DL |
last post by:
Hi,
What I wanted to do is to call a function from a newly created
element. But it stumbled me.
Here's the line that references the newly created element and I used
the alert function for...
|
by: Paladius |
last post by:
Hello,
Within my Access program I create a new database using VBA. After the new database is created, I would like to set a form in it to appear on startup.
I have tried using...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |