Im a bit stuck!
Im new to python coding and this is my second project and Ive hit a wall.
basically Ive made a GUI with 12 radio buttons in 3 sets, (3,3,6) plus an "execute" button, plus various other scripts to execute certain GPIO outputs.
what i want is to be able to select 3 options from the GUI and when i hit the "execute" button for it to run the appropriate .py file
i have got it working to return a value from the 3 variables like so:
def sel():
X = dr1.get()
Y = dr2.get()
Z = dr3.get()
return X+Y+Z
this gives me a value for example of "appleorangebanana"
or with different radio buttons selected a value of "applegrapebanana"
all possible returned values have a corresponding .py file saved with its own script.
where im getting stuck is using the returned value to run the right file when i hit the "execute" button
thanks for any help
Related
My project has multiple tkinter functions that create windows and different buttons have different buttons that connect to the main program. One issue I have is that when I call a tkinter gui function the images are not displayed.
def get_userInfo(user,pass):
login_state = db.login_verification(user,pass) # Returns either True / False
if login_state == True:
full_name = db.retrive(user,pass,id) # Get's Full name from database.
gui.user_page(first_name) # This only displays the window with no images / text.
gui.user_page("john") # This works perfectly tho
When I call a function within a function the images from the assets path do not load.
Whereas if I just do gui.user_page from outside the function it works without any issues.
I think if I were to use more classes in my gui.py file it should probably fix the issue.
I am trying to write my 1St Maya Python Script......I know I have a ways to go before I don't keep getting dozens of Syntax Errors....But it's a simple script with no UI, and any even tidbits or clues I can get to get it to work will set me off with scripting.
Just a simple fuction of 'Clicking and dragging' visibilities on or off of the Display Layer boxes..the main function I am trying to define is:
draggerContext?
or
cmds.selectPref(clickBoxSize=True)
how to implement the fuction on/off..
any clues would be of help as the trickiest part of this script is defining the Function of CLick Drag select...
Thanks
my script that does not work yet:
import maya.cmds as cmds
#Click and drag to Turn On/Off Visibilities of the Display Layers
draggerContext_id = "dga"
def dga():
cmds.selectPref(clickBoxSize=True)
cmds.selectcmds.selectPref(clickBoxSize=True)
if:
clickdragBoxSize.sel=True(layerEditorLayerButtonVisibilityChange):
cmds.selectPref(clickBoxSize=True)
else:
cmds.select(layerEditorLayerButtonVisibilityChange=True)
SelectLayerEditorButtonVisibility()
first of all let me start off by saying I started coding around 6 weeks ago in self-study, so it is very likely, that the approach may still be a total mess.
I have a program running (fine for me) in cli, but I want to make it usable for people that faint, when they see plain white text on a black background which they have to operate without a mouse.
Besides my main window, which is running in the background I wanted to have a message window, which displays the information if all necessary files where selected. which is shown below.
files_to_open = {'File_1':'', 'File_2':'', 'File_3':''}
def selectfiles_window():
global message_window
message_window = Tk()
...
content = Label(message_window, text=get_open_file_status_txt(), **txt_status_general)
content.pack(side='top')
button_select_file1 = Button(message_window,text = 'File 1',font = txt_general['font'],command = lambda:(
select_file_action(name='File 1', filetypename='Excel workbook', extension='*.xlsx'),
content.configure(text=get_open_file_status_txt())))
button_select_file1(side='bottom')
message_window.mainloop()
def select_file_action(name, filetypename, extension):
global files_to_open
files_to_open[name] = filedialog.askopenfilename(title = f'Select {name}', filetypes=[(filetypename, extension)])
def get_open_file_status_txt():
global files_to_open
message =f'''
[File_1] is {"NOT SET" if (files_to_open["File_1"] == "") else "SET"}'''
return message
I expected, that the text is updated after the filedialog was closed (which is partly working as expected).
Now what I don't understand: If I click the button to select File_1 and cancel it for the first time, the value for key File_1 is set to (). Any time after that, if I click the button to select File_1 and cancel it, the value for key File_1 is set to ''. If I select a file the path is saved correctly as value (also on the first attempt). If I cancel it is set again to ''.
Anybody an idea about why the value is set to () on the first cancel but afterwards runs as expected?
I would also be grateful for a different solution to update the text, if my approach is totally off.
Thank you and best regards,
Thomas
Turns out, that the function call was not the issue, rather that it is a (strange to me but maybe intended) behavior of filedialog.askopenfilename, which returns an empty tuple if cancel is selected on first call but an empty string on every further canceled calls.
So I've created a GUI for a program I'm writing, and what I'm currently stuck on is the running of the calculations I want it to perform. I've done everything in Python 3.5, with a Kivy GUI build string to create the tabs (using tabbed panel and screen manager). I've got a button at the bottom of the tab to which this question pertains which says "Calculate" and should be taking the values of the text entries and operating them as part of the equation I want them to do.
Is the
.get
function going to be helpful in this case for doing this, or do I want to call more like:
class TabSys(TabbedPanel):
def calculate_psc_clicked(self):
#when they click the button which is id'd as "calculate_psc," this function
#will pull the values and perform the calculations
self.Cp_entry = self.Cp_entry.text
self.P_entry = self.P_entry.text
self.lhv_entry = self.lhv_entry.text
The above code is the TabSys class for my build string in kivy language, after it comes the
class nyce_meemApp(App):
def build(self):
return TabSys()
if __name__ == '__main__':
nyce_meemApp().run()
To actually run all the code. I don't want to inundate the question with code, so I'll leave it there, and I can put up any other pieces of code that anybody wants (if need be I can share the file).
Thanks
I'm quite new to Python and have been unsuccessful in finding a way around this problem. I have a GUI using TKinter that displays an image using Label. I would like the user to be able to click on two places in the image and use those two pixel locations elsewhere.
Below is the basic code I'm using so far, but I'm unable to return the pixel locations. I believe bind is not what I want to use, is there another option?
px = []
py = []
def onmouse(event):
px.append(event.x)
py.append(event.y)
return px,py
self.ImgPanel.bind('<button-1>',onmouse)
If I try to use:
px,py = self.ImgPanel.bind('<button-1>',onmouse)
I get an error "Too many values to unpack"
bind is what you want, if you want to capture the x,y coordinate of the click. However, functions called from bindings don't "return". Technically they do, but they return a value to the internals of Tkinter.
What you need to do is set an instance or global variable within the bound function. In the code you included in your question, if you add global px,py, you can then use those values in other code.