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 1383 dwblas 626
Recognized Expert Contributor
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 attempting to do this by using an anchor point name of an anchor
located
|
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> * f() {
vector<int> * v = new vector<int>;
return v;
}
|
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 always works becuase the image has
been fully saved to that drive by that time. Is there a way to make sure
that a newly created bitmap image is phisically saved to disk before it is
accessed?
The code that creates that new bitmap image is as...
|
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 (setting breakpoint in page_load()). I'm
getting the following message:
"Unable to start debugging on the web server. An error occurred that usually
indicates a corrupt installation (code 0x80004002). If the problem persists,
|
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 textbox. The ASP page
has a textbox (txtYourName) and a button. Clicking the button
will run this piece of code:
| |
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 selecting "Add...".
It opens up a window, where we hav to specify the name of the user, and the various privileges to the new user.
if we click"ok" the new user is created.
BUT THE PROBLEM IS I DON'T KNOW WAT IS THE PASSWORD (or DEFAULT PASSWORD)...
|
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");
eWin2.setAttribute( 'id', 'win2' );
eWin2.setAttribute( 'name', 'win2' );
eWin2.setAttribute( 'class', 'window' );
** eWin2.style.backgroundColor = 'yellow';
|
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 to the new row? I have created a method that calls the AddNew method on a DefaultView and creates a new row. I need to move to that newly created row and get the value from a auto-incremented cell in the new row and then populate a combo box with...
|
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 debugging for now. Did I mess up all these
quotes?
// once again this is the key line of code, problem area, disregard
|
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 CurrentDb.Properties("StartupForm")
but am not sure what I need to replace CurrentDB with in order to target the newly created DB.
or
Is their any way to export my "startup properties" of the current database to the newly created database?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |