Another newbie question about buttons
I've used Pythoncard to create my gui. Here it is in heavily condensed form:
import os
import sys
import os.path
import Tkinter
import wx
import subprocess
import subprocess as sp
from subprocess import Popen
from tkFileDialog import askopenfilenames
from tkFileDialog import askdirectory
import tkMessageBox
from Tkinter import *
from pathman import path
from PythonCard import dialog, model
from PythonCard.components import button, statictext, radiogroup
class VidToad(model.Background):
def choosein(self, event):
dlg = wx.DirDialog(self, "Choose Source folder...:", r'D:\\', style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
if dlg.ShowModal() == wx.ID_OK:
global indirname
indirname=os.path.normpath(dlg.GetPath())
dlg.Destroy()
def on_radiogroup_select( self, event ) :
global Formatname
Formatname=self.components.radiogroup.stringSelection
def on_Button1_mouseClick(self, event):
if Formatname=="stretch":
self.index_push()
self.think()
My question is how can I make Button1 disabled once it has been clicked and another process (self.index_push(()has begun. Everything I've tried has given me attribute or similar errors. I still haven't quitegot Python!
Thanks in advance!
floatingshed
Junior Poster in Training
66 posts since Feb 2012
Reputation Points: 23
Solved Threads: 1
You have not declared Button1 in the code you posted so there is nothing to disable. But generally it is
b.config(state=DISABLED)
where "b" is the button's ID as returned by Tkinter. Also, you import Tkinter in two different ways (pick one only)
import Tkinter
from Tkinter import *
Do not mix wxPython and Tkinter
import Tkinter
import wx
"os.path" is available once you import os
import os
import os.path
And you only have to import subprocess once.
import subprocess
import subprocess as sp
from subprocess import Popen
One of Grayson's examples (click "He's dead" to disable)
from Tkinter import *
def disable_button():
b1.config(state=DISABLED)
root = Tk()
root.title('Buttons')
Label(root, text="You shot him!").pack(pady=10)
b1=Button(root, text="He's dead!", command=disable_button)
b1.pack(side=LEFT)
Button(root, text="He's completely dead!", command=root.quit).pack(side=RIGHT)
root.mainloop()
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
You have not declared Button1 in the code you posted so there is nothing to disable.
This is Pythoncard so the button setup is contained in the resource file. As I understand it Python card is a "wrapper" or similar to wx, so I guess I should stick to wx. How would I disable the button in wx?
Thanks for all the tips on writing better code. I shall tidy it up now!
floatingshed
Junior Poster in Training
66 posts since Feb 2012
Reputation Points: 23
Solved Threads: 1
You have to have access to the button object and set enabled to False. I don't know of anyone here who uses PythonCard so we can't help much.
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714