Python program not responding [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Have been trying to run my program for several times, the icon and window is there but it's not responding. This actually might have something to do with looping but I'm not sure how to solve this. Is anyone able to help me out with this? Many thanks.
Looping is needed for combobox list.
Here is the code:
No errors found in the shell
from tkinter import *
from tkinter.ttk import *
from tkinter import ttk
import tkinter as tk
import pandas as pd
def CurSelet(evt):
global sel
temp=list()
for i in lbox.curselection():
temp.append(lbox.get(i))
allitems=list()
#for i in range(lbox.size()):
#allitems.append(lbox.get(i))
for i in sel:
if i in allitems:
if i not in temp:
sel.remove(i)
for x in lbox.curselection():
if lbox.get(x) not in sel:
sel.append(lbox.get(x))
def update_list():
global sel
global l
search_term = search_var.get()
# Just a generic list to populate the listbox
lbox_list = Device
lbox.delete(0, END)
for item in lbox_list:
if search_term.lower() in item.lower():
lbox.insert(END, item)
allitems=list()
for i in sel:
if i in allitems:
lbox.select_set(lbox.get(0, "end").index(i))
#search box
search_var = StringVar()
search_var.trace("w", lambda name, index, mode: update_list())
searchbox = tk.Entry(window, width=20, textvariable=search_var)
searchbox.place(x = 90, y =60)
lbox = Combobox(window, width=30, height=4)
lbox.place(x=90,y=90)
lbox.bind('<<ComboboxSelected>>',CurSelet)
update_list()

Add break to this line and stop the looping
for item in lbox_list:
if search_term.lower() in item.lower():
lbox.insert(END, item)
break

Related

Get python radio button value [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 days ago.
Improve this question
import tkinter as tk
I want to print the sr variable outside the function name, but it doesn't work. What should I do? help
import tkinter as tk
win = tk.Tk()
win.title('Test')
rpm_frame = tk.LabelFrame(win, text='샘플링 주파수')
rpm_frame.pack()
def get_sample():
if sample_var.get() == 1:
sr = 48000
ts = 1 / sr
print(sr)
if sample_var.get() == 2:
sr = 2000
ts = 1 / sr
print(sr)
sample_var = tk.IntVar()
sample_48000 = tk.Radiobutton(rpm_frame, text='48000', value=1, variable=sample_var, command=get_sample)
sample_2000 = tk.Radiobutton(rpm_frame, text='2000', value=2, variable=sample_var, command=get_sample)
sample_48000.pack()
sample_2000.pack()
win.mainloop()

Trying to Grab Data Entry from Treeview to Create a command

Hi Guys currently working on POS system I almost have it finished just trying to create a Remove Item Function I'm using a Treeviewer List to display my item currently in the cart. I'm trying to make a Remove Item function and I want to get the price of the Item that is currently selected in the Treeviewer list and - the value of the item off the Total.
Just want help with getting data from the Treeview list I can do everything else. Thanks
This is my Treeview List
scroll_x = Scrollbar(ChangeButtonFrame, orient=HORIZONTAL)
scroll_y = Scrollbar(ChangeButtonFrame, orient=VERTICAL)
self.POS_records=ttk.Treeview(ChangeButtonFrame, height=20,columns=("Item","Qty","Amount"),
xscrollcommand=scroll_x .set, yscrollcommand=scroll_y .set)
scroll_x.pack(side=BOTTOM, fill=X)
scroll_y.pack(side=RIGHT, fill=Y)
self.POS_records.heading("Item",text="Item")
self.POS_records.heading("Qty",text="Qty")
self.POS_records.heading("Amount",text="Amount")
self.POS_records['show']='headings'
self.POS_records.column("Item",width=120)
self.POS_records.column("Qty",width=100)
self.POS_records.column("Amount",width=100)
self.POS_records.pack(fill=BOTH, expand=1)
self.POS_records.bind("<ButtonRelease-1>")
As seen when a button is pressed it enters the value defined in that function
here is an example
def Coffee1():
ItemCost = 3.70
Tax = 10
self.POS_records.insert("", tk.END, values=("Americano", "1", "3.70"))
for child in self.POS_records.get_children():
ItemCost += float(self.POS_records.item(child, "values")[2])
SubTotal_Input.set(str('$%.2f'%(ItemCost-3.70)))
GST_Input.set(str('$%.2f'%(((ItemCost-3.70)* Tax)/100)))
Total_Input.set(str('$%.2f'%((ItemCost-3.70) + ((ItemCost-3.70)* Tax)/100)))
I Have what is currently selected in my function as of now just don't know how to continue.
(Currently what I've done in the function)
def RemoveItem():
selected_item = (self.POS_records.selection())
self.POS_records.delete(selected_item)
Im trying to create a remove item function that grabs the price from the treeview and then ill use that data to calculate the SubTotal_Input, GST_Input and Total_Input.
Thanks Any help appreciated :)

I am building a GUI for my app but get errors. Why? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to make a GUI to my app using tkinter but it doesn't work. why? The program needs to take 2 inputs from user and save them in variables also I marked where I got errors in the code below
import tkinter as tk
# making the window
root = tk.Tk()
root.title("AutoWhatsUp")
root.geometry('500x500')
# getting phone number from user
enter_number = tk.Label(root, text = "enter below the phone number you want to message")
enter_number.pack()
filed = tk.Entry(root)
filed.pack()
def get_number():
phone_num = filed.get()
done_procces_phone = tk.Label(root, text = 'Phone number procced!').pack() # getting error here
confirm_number = tk.Button(root, text = 'procces number', command = get_number).pack() #getting error here
# getting the message
enter_mess = tk.Label(root, text = 'enter below the message').pack() #getting error here
enter_mess_here = tk.Entry(root).pack() #getting error here
def getting_message():
message_here = enter_mess_here.get()
print(message_here)
done_procces_mess = tk.Label(root, text = "done!").pack() #getting error here
get_mess = tk.Button(root, text = "procces message", command = getting_message).pack() #getting error here
root.mainloop()
Your problem is you put None in your variable enter_mess_here here:
enter_mess_here = tk.Entry(root).pack() #getting error here
and in your function when you want to get the value it's not getting value from Entry it's getting from Nothing. So it raises an error.
First assign your Entry to a variable then use pack, so this will work:
enter_mess_here = tk.Entry(root)
enter_mess_here.pack()

Tkinter: how to get a string from a top-level entry? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
In tkinter, how can I .get() the entry from a top level window?
def logika(event):
a=e.get()
def pocetak(event):
igra=Toplevel(glavni)
igra.geometry("500x500+710+290")
e=Entry(igra)
e.pack()
GumbIgra=Button(igra,text="Unos")
GumbIgra.bind("<Button>",func=logika)
GumbIgra.pack()
return
glavni=Tk()
glavni.geometry("600x600")
glavni.resizable(True,True)
glavniGumb=Button(glavni,text="Za početak stisni me!",pady=10,padx=15)
glavniGumb.config(font=("Arial",10))
glavniGumb.bind("<Button>",func=pocetak)
glavniGumb.pack()
It seems more like the logika(event) function is unable to figure out what is e. You will have to pass the object.
So something like this (untested):
from tkinter import *
#Creating main window
root = Tk()
def Input_Box():
# creating a top window
master_2 = Toplevel(root)
#Textboxes
user_name = Entry(master_2)
user_name.grid(row = 1, column = 2)
pwd = Entry(master_2)
pwd.grid(row = 2, column = 2)
label_un = ttk.Label(master_2, text = "Username")
label_un.grid(row = 1, column = 1)
label_pwd = ttk.Label(master_2, text = "Password")
label_pwd.grid(row = 2, column = 1)
get_button = Button(master_2, text = "Confirm", command = lambda: getname(user_name))
get_button.grid(row=3, column = 1)
master_2.mainloop()
def getname(user_name):
input = user_name.get()
print(input)
call_button = Button(root, text='Enter Usrnm and pwd', command = Input_Box)
call_button.pack()
root.mainloop()
The command = lambda: getname(user_name) passes the user_name object that refers to the textbox.
Hope this helps!
Please give us the exact error.
PS: This was for something else but I think this should help.

Python Tkinter Gui Not Working

I have had an issue with this piece of code from awhile back, it's part of a GCSE mock and I have currently finished the working code (with text only) but I would like to expand it so that it has a nice GUI. I'm getting some issues with updating my sentence variables within the code. Anyone with any suggestions for me please do explain how I can fix it.
#GCSE TASK WITH GUI
import tkinter
from tkinter import *
from tkinter import ttk
var_sentence = ("default")
window = tkinter.Tk()
window.resizable(width=FALSE, height=FALSE)
window.title("Sentence")
window.geometry("400x300")
window.wm_iconbitmap("applicationlogo.ico")
file = open("sentencedata.txt","w")
file = open("sentencedata.txt","r")
def update_sentence():
var_sentence = sentence.get()
def submit():
file.write(sentence)
print ("")
def findword():
messagebox.showinfo("Found!")
print ("Found")
sentencetext = tkinter.Label(window, fg="purple" ,text="Enter Sentence: ")
sentence = tkinter.Entry(window)
sentencebutton = tkinter.Button(text="Submit", fg="red" , command=update_sentence)
findword = tkinter.Label(window, fg="purple" ,text="Enter Word To Find: ")
wordtofind = tkinter.Entry(window)
findwordbutton = tkinter.Button(text="Find!", fg="red" ,command=findword)
usersentence = sentence.get()
usersentence = tkinter.Label(window,text=sentence)
shape = Canvas (bg="grey", cursor="arrow", width="400", height="8")
shape2 = Canvas (bg="grey", cursor="arrow", width="400", height="8")
#Packing & Ordering Moduales
sentencetext.pack()
sentence.pack()
sentencebutton.pack()
shape.pack()
findword.pack()
wordtofind.pack()
findwordbutton.pack()
usersentence.pack()
shape2.pack()
window.mainloop()
If I understand your question right, you want to display the entered text in the usersentence label.
Changing update_sentence() function to what is shown below will archive the desired effect.
def update_sentence():
var_sentence = sentence.get()
usersentence.config(text=var_sentence)
usersentence never gets updated because you only set it once when the program starts this was the problem.

Categories

Resources