I'm new to coding, so I apologize if I'm making a really dumb mistake.
I have one module (INPUT_GUI.py) that opens a window where my user can input information, then hit a submit button.
I have another module (Error_Check.py) that I want to use to look over the inputs for errors. If there is an error, it throws up a message box "You dun goofed bud" which they can close and correct their input error (INPUT_GUI frame hasn't closed yet). The Error_Check.py should run each time the submit button is clicked.
I want to call both of these modules from Input_Master.py, which I want to close the INPUT_GUI frame if there were no errors.
Right now, when I run the Input_Master, I don't get anything. I've got a print command in there to show me the values it grabs from the Input GUI, but I just see a 0.
What am I doing wrong?
GUI_INPUT.py:
from tkinter import *
from tkinter import ttk
Input_Table = 0
def retrieve(): #returns the input values as a dictionary
global Input_Table
Input_Table={1:[inputA1.get(),inputB1.get()],2:[inputA2.get(),inputB2.get()]....}
return(Input_Table)
def Close_Input():
root.destroy()
def Input_Table_Gen():
root=Tk()
frame1=Frame(root)
frame1.pack(fill=x)
frame2=Frame(root)
frame2.pack(fill=x)
#...
frame11=Frame(root)
frame11.pack(fill=x)
inputA1=Entry(frame1,width=20)
inputA1.pack(side=LEFT,padx=5,pady=5)
inputB1=Entry(frame1,width=20)
inputB1.pack(side=LEFT,padx=5,pady=5)
#...
inputA10=Entry(frame1,width=20)
inputA10.pack(side=LEFT,padx=5,pady=5)
inputB10=Entry(frame1,width=20)
inputB10.pack(side=LEFT,padx=5,pady=5)
Submit_Button = Button(frame11,text="Submit",command=retrieve)
Submit_Button.pack()
root.mainloop()
Error_Check.py:
From GUI_INPUT import retrieve
x = {}
def Input_Errors(x)
#checks for errors, returns True if errors are found, and False if no errors are found
Input_Master.py:
import GUI_INPUT
from Error_Check import Input_Errors
GUI_INPUT.Input_Table_Gen
Error_Output = Error_Check.Input_Errors(Input_Table)
if Error_Output = True:
messagebox.showinfo("ERROR","You dun goofed, try again plz")
else:
GUI_INPUT.Close_Input
Related
I want to define a widget button (named start in this case) that when I press it, starts to ask for an input from the user.
Here is the code I use:
from IPython.display import display
import ipywidgets as widgets
Start_button = widgets.Button(description="Start")
Start_output = widgets.Output()
display(Start_button, Start_output)
def Start_button_clicked(b):
with Start_output:
print("test Button clicked.")
test = input('input')
Start_button.on_click(Start_button_clicked)
But it gives me EOFError: EOF when reading a line
Any idea how to fix this?
I'm using several tkinter messageboxes in my code. But ive noticed a problem with the showinfo messageboxes I've used in my code. Basically, I want a function to be called when the ok on the messagebox is pressed. Also, the user can choose not to proceed by just closing the messagebox. But, it looks like when I press the x icon to close the messagebox, the function is still called. Here is a minimum reproducible code to explain what i mean.
from tkinter import *
from tkinter import messagebox
root = Tk()
def func() :
Label(root,text="This is the text").pack()
msg = messagebox.showinfo("Loaded","Your saved state has been loaded")
if msg == "ok" :
func()
root.mainloop()
My question is, What should i do so that the function is not called when the x icon is pressed?
There are different types of messagebox, the one your using here is not what you actually should be using for your case. What you want is something called askyesno, or something that is prefixed by 'ask' because your code depend upon the users action. So you want to 'ask' the user, like:
from tkinter import *
from tkinter import messagebox
root = Tk()
def func() :
Label(root,text="This is the text").pack(oadx=10,pady=10)
msg = messagebox.askyesno("Loaded","Your saved state has been loaded")
if msg: #same as if msg == True:
func()
root.mainloop()
Here, askyesno like other 'ask' prefixed functions will return True or 1 if you click on the 'Yes' button, else it will return False or 0.
Also just something I realized now, showinfo, like other 'show' prefixed messagebox function, returns 'ok' either you press the button or close the window.
Some more 'ask' prefixed messageboxes ~ askokcancel, askquestion, askretrycancel, askyesnocancel. Take a look here
I have an entry field in my window and I want to type someting in the entry field,
press enter, and something happends, but it doesnt work because the curser is still in the entry field when I press enter after I typed someting
here is the code ive been using oversimpified (the for this question non important parts left out)
from tkinter import *
def some_func():
#other code I want to happen when I press enter
root = Tk()
entry_one_root = Entry(root).place(x=0, y=0)
root.mainloop()
Is there a way to fix that?
thx for your help
Is this what you're looking for ?
import tkinter as tk
root = tk.Tk()
entry = tk.Entry(tk.root)
def some_func():
...
# Bind enter key on entry to some_func
entry.bind("<Enter>", lambda event: some_func())
root.mainloop()
I'm trying to do a script in tkinter. Good to know: I'm kind of new to python.
The script takes user input to find the user input on a server. First time I run the script it works fine, but when trying to find something new the script gives me the error: AttributeError: 'str' object has no attribute 'get' So im guesseing that the user input/Button needs to be reset some how. And I donĀ“t understand why it works the first time and not the second time.
I've tried to find a good way to do this, but I have failed. Please halp a newbie.
import requests, re, urllib.request
import tkinter as tk
from tkinter import *
from tkinter import ttk
window = Tk()
window.title("Find answer")
ttk.Label(window, text="What you wanna find: ").pack()
stuff = ttk.Entry(window)
stuff.pack()
frame = Frame(window, width=200, height=50)
frame.pack()
servers = ["192.168.8.3", "192.68.8.2"]
def find():
global stuff
stuff = stuff.get()
stuff = stuff.lower()
for server in servers:
f = urllib.request.urlopen("http://"+server+"/find")
result = f.read().decode('utf-8')
lab = tk.Label(frame,text="server")
lab.pack()
print(server)
def clicked_start():
find()
start_btn = ttk.Button(text="Find the stuff", command=clicked_start)
start_btn.pack(fill="none")
window.mainloop()
i guess the reason is that you redefine stuff
global stuff
stuff = stuff.get()
stuff = stuff.lower()
the variable is originally an Entry Object, you redefine it as a string
Try to use another variable, eg
global stuff
stuffcontent = stuff.get()
stuffcontent = stuffcontent.lower()
I'm currently trying to write in a few basic user input boxes using the tkinter module in Python 3.6 (via Spyder). I can confirm that the module loads, and that the option to select simpledialog comes up, but I keep getting the following error:
AttributeError: module 'tkinter' has no attribute 'simpledialog'
Image of tkinter simpledialog
I've tried to look for other options, but other user input options do not seem to work on my Python interface. It either crashes, or the data isn't structured properly.
Interestingly enough, in the past, I've done similar things in Python with no errors, but this keeps coming up with this particular programming piece.
import tkinter as tk
import pyodbc as py
py.pooling = False
## INPUT YOUR USER ID AND PASSWORD AND DECLARE YOUR CONNECTION
## THE DIALOG BOXES MAY POP OPEN ON ANOTHER SCREEN
## THE PASSWORD INPUT IS MASKED AND WILL NOT SHOW IN THE
## VARIABLE EXPLORER
ID = tk.simpledialog.askstring("Please input your username.","Username: ")
PW = tk.simpledialog.askstring("Please input your password.",
"Password: ", show='*')
CONN = tk.simpledialog.askstring("Please input your connection.",
"Connection: ")
My expected results are that a popup window will appear and that I'll be able to get the user information I need to maintain a stable connection to the server I'm using.
Thank you in advance for your advice!
simpledialog is not in tkinter but in tkinter.simpledialog and you have to import it
import tkinter as tk
import tkinter.simpledialog
root = tk.Tk() # create main window
#root.iconify() # minimize main window
root.withdraw() # hide main window
answer = tkinter.simpledialog.askstring("Question", 'Your name:')
print(answer)
#root.destroy() # should work without it
#root.mainloop() # should work without it
See tkinter modules
import tkinter as tk
from tkinter import simpledialog
root = tk.Tk()
ID = simpledialog.askstring("Please input your username.", "Username: ", parent=root)
root.mainloop()
This will keep the popup within the parent window and visible.