CS-Lab Support Forum for CNC Community

Help to run this brand-new forum and stay with us.
Ask your questions, we are here to help! 

 

Forum Navigation
You need to log in to create posts and topics.

numeric input form for touchscreens

hello,

i am working on a python based form to enter value's by touchscreen into machine parameters and LineEdit widget's

got it working for machine parameters but line edit widget drives me creasy.

if i test this code:


  myObjekt ="TXT_Geschwindigkeit"
  USRcontrol = getattr(gui, myObjekt)
  print(USRcontrol.getText())

everything works like expected

if i try to do the same in in a class


class numerickeyboard():
  def __init__(self,paramNummer,Min,Max,Funktion):
    #Paramter holen
    self.paramNummer = paramNummer
    self.Min = Min
    self.Max = Max
    self.Funktion = Funktion
    self.Language = (d.getScreenName( ) [-2:]).upper()

    #aktuellen Wert anhand der Funktion lesengetGCodeMinPosition( CoordMode coordMode )
   if Funktion == 1: # Maschineparameter
     self.wert = str(d.getMachineParam(paramNummer))
   if Funktion == 2: # USR Parameter textbox
      #textbox finden
      USRcontrol = getattr(gui, paramNummer)
      self.wert = USRcontrol.getText( )
      print(self.wert)


cases errors
even if i import everything by

from ___DEVICE import *
from ___GUI import * 
gui=Gui()
d=Device()

not sure what i am doing wrong.
sorry for my dump question's but i am brand new to python

regards Tom



​Please share all the code and also errors from the console.
 

as soon i am try to upload my scripts i get this error:

 

Uploaded files:
  • ErrorCSLabForum.png

ok, not allowed to upload .py files, not alloed to upload .zip files,  not allowed to upload textfiles, then lets try this

 

test.py


from NumericInput1 import *

#Param = 104
Param = "gui.ed_BandGeschwindigkeit"
Min = 0
Max = 100
Einheit = "mm/s"
Format = "{0:.0f}"

#Aufruf keypad
if type(Param) is int:
numerickeyboard(Param, Min , Max , Format, Einheit,1)
else:
numerickeyboard(Param, Min , Max , Format, Einheit,2)

#update Anzeige Eingabefeld
#template = Format + " " + Einheit
#text = template.format(d.getMachineParam(Param))
#gui.ed_BandGeschwindigkeit.setText(text)


NumericInput1.py


################################################################################
# Script zur Eingabe von numerischen Werten
# TPS 02.12.2025
# Aufruf numerickeyboard(Parameternummer, Min , Max , Format, Einheit, Funktion)
# Funktionsnummern:
# 1=MachineParam
# 2=USR value textbox
#
# Sprachen(werden aus der Endung der ScreenSets entnommen) z.B. _DE:
# EN
# DE
#################################################################################
#import sys
#import time
from enum import Enum
from tkinter import *
from tkinter import ttk
import tkinter.font as font
from ___DEVICE import *
#from ___GUIUPD import getUserWidgets
#from ___GUIUPD import * #getScriptsPath
from ___GUI import * #Gui
#g=Gui()
d=Device()

class numerickeyboard():
def __init__(self,paramNummer,Min,Max,Format,Einheit,Funktion):
#Paramter holen
self.paramNummer = paramNummer
self.Min = Min
self.Max = Max
self.Format = Format
self.Einheit = Einheit
self.Language = (d.getScreenName( ) [-2:]).upper()

#aktuellen Wert anhand der Funktion lesen
if Funktion == 1: # Maschineparameter
self.wert = str(d.getMachineParam(paramNummer))
if Funktion == 2: # USR Parameter textbox
USRcontrol = getattr(gui, paramNummer)
# self.wert = USRcontrol.getText( )

#textbox finden
# for i in getUserWidgets() :
# if i[1] == paramNummer:
# USRcontrol = getattr(gui, i[1])
# self.wert = USRcontrol.getText( )
# if self.wert =='':
# self.wert = '0'

#Texte anhand der uebergeben Sprache einstellen
if self.Language == "DE":
title = "Wert eingeben. Min: " + str(Min) + " Max: " + str(Max)
okButton = "Fertig"
canButton = "Abbrechen"
if self.Language == "EN":
title = "enter value. min: " + str(Min) + " max: " + str(Max)
okButton = "finished"
canButton = "cancel"

self.root = Tk()
self.root.title(title)
self.root.geometry("340x680")
self.root.attributes('-topmost', True)

s = ttk.Style(self.root)
s.theme_use('clam')
s.configure('raised.TButton', borderwidth=0)
s.configure('my.TButton', font=('Arial', 16))

# Label und Buttons erstellen.
self.but_7 = ttk.Button(self.root, text="7", style='my.TButton', command=self.but_7)
self.but_8 = ttk.Button(self.root, text="8", style='my.TButton', command=self.but_8)
self.but_9 = ttk.Button(self.root, text="9", style='my.TButton', command=self.but_9)
self.but_4 = ttk.Button(self.root, text="4", style='my.TButton', command=self.but_4)
self.but_5 = ttk.Button(self.root, text="5", style='my.TButton', command=self.but_5)
self.but_6 = ttk.Button(self.root, text="6", style='my.TButton', command=self.but_6)
self.but_1 = ttk.Button(self.root, text="1", style='my.TButton', command=self.but_1)
self.but_2 = ttk.Button(self.root, text="2", style='my.TButton', command=self.but_2)
self.but_3 = ttk.Button(self.root, text="3", style='my.TButton', command=self.but_3)
self.but_D = ttk.Button(self.root, text=".", style='my.TButton', command=self.but_D)
self.but_0 = ttk.Button(self.root, text="0", style='my.TButton', command=self.but_0)
self.but_B = ttk.Button(self.root, text="<-", style='my.TButton', command=self.but_B)
self.but_N = ttk.Button(self.root, text="+/-", style='my.TButton', command=self.but_N)
self.but_Del = ttk.Button(self.root, text="Del", style='my.TButton', command=self.but_Del)

self.exit_button = ttk.Button(self.root, text=okButton, style='my.TButton', command=self.but_OK)
self.cancel_button = ttk.Button(self.root, text=canButton, style='my.TButton', command=self.but_Can)

self.wert_label = ttk.Label(self.root, text=self.wert + " " + self.Einheit, style='my.TButton')

# Nun fügen wir die Komponenten unserem Fenster
# in der gwünschten Reihenfolge hinzu.

self.but_7.place(x = 10 , y = 10, width=100, height=100)
self.but_8.place(x = 120 , y = 10, width=100, height=100)
self.but_9.place(x = 230, y = 10, width=100, height=100)
self.but_4.place(x = 10 , y = 120, width=100, height=100)
self.but_5.place(x = 120 , y = 120, width=100, height=100)
self.but_6.place(x = 230, y = 120, width=100, height=100)
self.but_1.place(x = 10 , y = 230, width=100, height=100)
self.but_2.place(x = 120 , y = 230, width=100, height=100)
self.but_3.place(x = 230, y = 230, width=100, height=100)
self.but_D.place(x = 10 , y = 340, width=100, height=100)
self.but_0.place(x = 120 , y = 340, width=100, height=100)
self.but_B.place(x = 230, y = 340, width=100, height=100)
self.but_N.place(x = 10 , y = 450, width=100, height=100)
self.but_Del.place(x = 120 , y = 450, width=100, height=100)

self.wert_label.place(x = 90, y = 560, width=150, height=50)

self.exit_button.place(x = 10, y = 620, width=150, height=50)
self.cancel_button.place(x = 170, y = 620, width=150, height=50)

self.bgcolor = self.wert_label["background"]

# In der Ereignisschleife auf Eingabe des Benutzers warten.
self.root.mainloop()

def writeWert(self):
if self.wert != "":
#Min/Max Begrenzung
if (float(self.wert) < self.Min) or (float(self.wert) > self.Max):
self.wert_label.config(background="red")
else:
self.wert_label.config(background=self.bgcolor)
else:
self.wert_label.config(background=self.bgcolor)

self.wert_label.config(text=self.wert + " " + self.Einheit)

def but_7(self):
self.wert = self.wert + "7"
self.writeWert()
def but_8(self):
self.wert = self.wert + "8"
self.writeWert()
def but_9(self):
self.wert = self.wert + "9"
self.writeWert()
def but_4(self):
self.wert = self.wert + "4"
self.writeWert()
def but_5(self):
self.wert = self.wert + "5"
self.writeWert()
def but_6(self):
self.wert = self.wert + "6"
self.writeWert()
def but_1(self):
self.wert = self.wert + "1"
self.writeWert()
def but_2(self):
self.wert = self.wert + "2"
self.writeWert()
def but_3(self):
self.wert = self.wert + "3"
self.writeWert()
def but_D(self):
if self.wert.find('.') == -1:
self.wert = self.wert + "."
self.writeWert()
def but_0(self):
self.wert = self.wert + "0"
self.writeWert()
def but_B(self):
self.wert = self.wert[:-1]
self.writeWert()
def but_N(self):
if self.wert[0:1] == "-":
self.wert = self.wert[1:]
else:
self.wert = "-" + self.wert
self.writeWert()
def but_Del(self):
self.wert = ""
self.writeWert()

def but_OK(self):
#Min Begrenzung
if float(self.wert) < self.Min:
self.wert = str(self.Min)
#Max Begrenzung
if float(self.wert) > self.Max:
self.wert = str(self.Max)
#aktuellen Wert Schreiben
d.setMachineParam(self.paramNummer, float(self.wert))

self.root.destroy()

def but_Can(self):
self.root.destroy()


test.py is "calling" NumericInput1.py

getting this error:


Traceback (most recent call last):

File "C:\Program Files\simCNC\profiles\BraetCNC\scripts\___INIT.py", line 34, in <module>

exec(open(fileName, encoding='utf-8').read())

File "<string>", line 14, in <module>

File "C:\Program Files\simCNC\profiles\BraetCNC\scripts\NumericInput1.py", line 40, in __init__

USRcontrol = getattr(gui, paramNummer)

NameError: name 'gui' is not defined

Script C:/Program Files/simCNC/screens/BraetCNC_de/scripts/test.py execution error (Unknown error: 1).

PARTNERS:

 

USA

Germany

Slovenia / Bosnia

Spain

South Africa

UNI-CAM

The Netherlands

Portugal

Greece

  Distrib milionis logo

Hungary

Distrib logot

Bulgaria

Master

Kenya

Proteq Automation

Egypt

Germanelectronix

China

Jun Ma

Serbia

ALCO

Italy

LVL tech r

Denmark

Varntoft Dania

Finland