Python Forum
GUI insert textbox value into a Class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GUI insert textbox value into a Class
#1
By modifing my gui with the TopLevel code (that i acquired from the forum), i have another problem. I want to pass inside the class that generates the Top level window the entry of text value (=pm6 textbox, line 200) that results after executing the first query (of main gui = w1, lines 22-23...). I set pm6 as a global variable (if it is not mistaken as a code), but the second query (inside the class) that gets pm6 value doesn't bring anything (line 133).

I need to set pm6 inside the toplevel class as a variable?

from tkinter import*
from tkinter import messagebox
import time
from datetime import datetime
from tkinter import ttk
import tkinter.messagebox as box
import tkinter as tk
import tkinter.font as tkFont
import tkinter.ttk as ttk1
import tkinter as tk2
from functools import partial
import cx_Oracle
 
 
def search():
 try:
   connstr='SOLVATIO/[email protected]'
   conn = cx_Oracle.connect(connstr)
   curs3=conn.cursor()
   curs5=conn.cursor()
   curs7=conn.cursor()
   curs3.execute("select  NAME_PROJECT_MCM,MODEL_E,CONTRACT_NUMBER,SUPPORT_LEVEL,SEARCHCODE_MCM,VENDOR_SUPPORT,"
                      +"to_char(customer_support_end_date, 'dd/mm/yyyy'),SUPPLY_TYPE,NEW_NAME_FULL_MCM, AFM_MCM, company_name_mcm from customer_mcm where SERIAL_NUMBER='%s'"%SERIAL_NUMBER.get())  
   results3=curs3.fetchone()
   NAME_PROJECT_MCM.set(results3[0])
   MODEL_E.set(results3[1])
   CONTRACT_NUMBER.set(results3[2])
   SUPPORT_LEVEL.set(results3[3])
   SEARCHCODE_MCM.set(results3[4])
   fSEARCHCODE_MCM=(results3[4])
   VENDOR_SUPPORT.set(results3[5])
   CUSTOMER_SUPPORT_END_DATE.set(results3[6])
   SUPPLY_TYPE.set(results3[7])
   NEW_NAME_FULL_MCM.set(results3[8])
   AFM_MCM.set(results3[9])
   company_name_mcm.set(results3[10])
 
 except:
    messagebox.showinfo('Μύνημα', 'No such data')
 
def clear2():
   SERIAL_NUMBER.set('')
   NAME_PROJECT_MCM.set('')
   MODEL_E.set('')
   CONTRACT_NUMBER.set('')
   SUPPORT_LEVEL.set('')
   SEARCHCODE_MCM.set('')
   VENDOR_SUPPORT.set('')
   CUSTOMER_SUPPORT_END_DATE.set('')
   SUPPLY_TYPE.set('')
   NEW_NAME_FULL_MCM.set('')
   AFM_MCM.set('')
   project_mcm_desc.set('')
   company_name_mcm.set('')    
#============================================================#
w1=Tk()
w1.title('GUI Special Solutions')
w1.geometry('1500x800+0+0')
 
pm6=IntVar()
 
 
#===============================Top Level=============================#
class OpenToplevels():
    """ open and close additional Toplevels with a button
    """
     
    def __init__(self):
        self.tree = None
        self.root = tk2.Tk()
        self.button_ctr=0
        but=tk2.Button(w1, text="Open a Toplevel",
                      command=self.open_another)
        but.grid(row=10, column=0)
 
  
    def close_it(self, id_top,container):
        id_top.destroy()
        container.destroy()
        self.button_ctr=0
         
    def open_another(self):
       self.button_ctr += 1
       if self.button_ctr==1:
        id_top = tk2.Toplevel(self.root)
        id_top.title("Toplevel #%d" % (self.button_ctr))
        container = ttk1.Frame(id_top)
        container.grid()
        # create a treeview with dual scrollbars
        self.tree = ttk1.Treeview(id_top,columns=car_header, show="headings")
        vsb = ttk1.Scrollbar(id_top,orient="vertical",
            command=self.tree.yview)
        hsb = ttk1.Scrollbar(id_top,orient="horizontal",
            command=self.tree.xview)
        self.tree.configure(yscrollcommand=vsb.set,
            xscrollcommand=hsb.set)
        self.tree.grid(column=0, row=0, sticky='nsew', in_=container)
        vsb.grid(column=1, row=0, sticky='ns', in_=container)
        hsb.grid(column=0, row=1, sticky='ew', in_=container)
        container.grid_columnconfigure(0, weight=1)
        container.grid_rowconfigure(0, weight=1)
        tk2.Button(id_top, text="Close Toplevel #%d" % (self.button_ctr),
                  command=partial(self.close_it, id_top,container),
                  bg="orange", width=20).grid(row=1, column=0)
 
         
        for col in car_header:
            self.tree.heading(col, text=col.title(),
                command=lambda c=col: sortby(self.tree, c, 0))
            # adjust the column's width to the header string
            self.tree.column(col,
                width=tkFont.Font().measure(col.title()))
  
        for item in car_list:
            self.tree.insert('', 'end', values=item)
  
        def sortby(tree, col, descending):
            """sort tree contents when a column header is clicked on"""
    # grab values to sort
            data = [(tree.set(child, col), child) \
             for child in tree.get_children('')]
            data.sort(reverse=descending)
            for ix, item in enumerate(data):
               tree.move(item[1], '', ix)
    # switch the heading so it will sort in the opposite direction
            tree.heading(col, command=lambda col=col: sortby(tree, col, \
            int(not descending)))
  
 
connstr='SOLVATIO/[email protected]'
conn = cx_Oracle.connect(connstr)
cursw = conn.cursor()
cursw.execute("select NAME_PROJECT_MCM, MODEL_E, CONTRACT_NUMBER , SERIAL_NUMBER,company_name_mcm, searchcode_mcm  from customer_mcm where searchcode_mcm='%s'"%pm6.get())      
car_list=list(cursw.fetchall())
car_header = ['NAME_PROJECT_MCM', 'MODEL_E', 'CONTRACT_NUMBER' , 'SERIAL_NUMBER','company_name_mcm', 'searchcode_mcm']
 
 
Ot=OpenToplevels()
 
#============================================================#
 
SERIAL_NUMBER=StringVar()
NAME_PROJECT_MCM=StringVar()
MODEL_E=StringVar()
CONTRACT_NUMBER=StringVar()
SUPPORT_LEVEL=StringVar()
SEARCHCODE_MCM=StringVar()
VENDOR_SUPPORT=StringVar()
CUSTOMER_SUPPORT_END_DATE=StringVar()
SUPPLY_TYPE=StringVar()
NEW_NAME_FULL_MCM=StringVar()
AFM_MCM=StringVar()
company_name_mcm=StringVar()
project_mcm_desc=StringVar()
fSEARCHCODE_MCM=StringVar()
 
#============================================================#
 
lpm1=Label (w1, font=('arial',9,'bold'),text='''Σειριακός Αριθμός :''')
pm1=Entry(w1, textvariable=SERIAL_NUMBER,bg='lavenderblush',fg='red')
lpm2=Label (w1, text='''Όνομα Έργου :''')
pm2=Entry(w1, textvariable=NAME_PROJECT_MCM, state='readonly', readonlybackground='mintcream')
bm3=Button(w1,text='Search SN',command=search,fg='blue')
bm4=Button(w1, text='Clear SN', command=clear2,fg='red')
lpm3=Label (w1, text='''Μοντέλο Εξοπλισμού :''')
pm3=Entry(w1, textvariable=MODEL_E, state='readonly', readonlybackground='mintcream')
lpm4=Label (w1, text='''Αριθμός Συμβολαίου :''')
pm4=Entry(w1, textvariable=CONTRACT_NUMBER,width=30, state='readonly', readonlybackground='mintcream')
lpm5=Label (w1, text='''Επίπεδο Υποστήριξης :''')
pm5=Entry(w1, font=('arial',9,'bold'),textvariable=SUPPORT_LEVEL, width=12, state='readonly', readonlybackground='mintcream')
lpm6=Label (w1, text='''Searchcode :''')
pm6=Entry(w1, textvariable=SEARCHCODE_MCM, state='readonly', readonlybackground='mintcream')
lpm7=Label (w1, text='''Vendor Support :''')
pm7=Entry(w1, textvariable=VENDOR_SUPPORT, state='readonly', readonlybackground='mintcream')
lpm8=Label (w1, text='''Υποστήριξη Πελατη έως :''')
pm8=Entry(w1, textvariable=CUSTOMER_SUPPORT_END_DATE, width=11, state='readonly', readonlybackground='mintcream')
lpm9=Label (w1, text='''Τρόπος Διάθεσης :''')
pm9=Entry(w1, textvariable=SUPPLY_TYPE, width=30, state='readonly', readonlybackground='mintcream')
lpm10=Label (w1, text='''Ονομασία Σημείου :''')
pm10=Entry(w1, textvariable=NEW_NAME_FULL_MCM, width=60, state='readonly', readonlybackground='mintcream')
lpm11=Label (w1, text='''Α.Φ.Μ :''')
pm11=Entry(w1, textvariable=AFM_MCM, width=15, state='readonly', readonlybackground='mintcream')
lpm12=Label (w1, text='''Επωνυμία :''')
pm12=Entry(w1, textvariable=company_name_mcm, width=15, state='readonly', readonlybackground='mintcream')
 
  
lpm1.grid(row=18,column=0,sticky=E)
pm1.grid(row=18,column=1)
lpm2.grid(row=19,column=0,sticky=E)
pm2.grid(row=19,column=1)
bm3.grid(row=18,column=2)
bm4.grid(row=25,column=0,sticky=E)
lpm3.grid(row=20,column=0,sticky=E)
pm3.grid(row=20,column=1)
lpm4.grid(row=19,column=2,sticky=E)
pm4.grid(row=19,column=3,sticky=W)
lpm5.grid(row=21,column=0,sticky=E)
pm5.grid(row=21,column=1,sticky=W)
lpm6.grid(row=22,column=0,sticky=E)
pm6.grid(row=22,column=1)
lpm7.grid(row=23,column=0,sticky=E)
pm7.grid(row=23,column=1)
lpm8.grid(row=24,column=0,sticky=E)
pm8.grid(row=24,column=1, sticky=W)
lpm9.grid(row=20,column=2,sticky=E)
pm9.grid(row=20,column=3, sticky=W)
lpm10.grid(row=21,column=2,sticky=E)
pm10.grid(row=21,column=3, sticky=W)
lpm11.grid(row=22,column=2,sticky=E)
pm11.grid(row=22,column=3, sticky=W)
lpm12.grid(row=23,column=2,sticky=E)
pm12.grid(row=23,column=3, sticky=W)
mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter Textbox only showing one character Xylianth 1 697 Jan-29-2021, 02:59 AM
Last Post: Xylianth
  [Tkinter] Redirecting stdout to TextBox in realtime Gilush 2 3,815 Jun-06-2020, 11:05 AM
Last Post: deanhystad
  tkinter how to unselect text in textbox Battant 0 1,058 Feb-17-2020, 02:00 PM
Last Post: Battant
  Tkinter Gui ScrolledText Insert From Different Class whisperquiet 1 2,861 Jan-08-2019, 09:25 PM
Last Post: Larz60+
  [Tkinter] cannot type in textbox msteffes 2 1,675 Jul-28-2018, 04:20 AM
Last Post: msteffes

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020