-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to connect some widget made in TTK Designer to another TTK Designer output #210
Comments
You can use the overlay helper I made an example using your code in: you can tryItOnline from TermTk import TTkUiLoader, TTk, TTkWindow, TTkLabel, TTkLog, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot
TTkLog.use_default_file_logging()
class MyTextEditor(TTkWindow):
def __init__(self, root):
self.root = root
TTkUiLoader.loadDict(
{'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},self)
self.textMyInput = self.getWidgetByName('licenseTxtInput')
self.checkButton = self.getWidgetByName('checkLicenseBtn')
self.checkButton.clicked.connect(self.onCheckButtonClick)
pyTTkSlot(str)
def onCheckButtonClick(self):
# You can use the log api to debug and print
# using the built in "print" would interfere with
# the drawing routine
TTkLog.debug(self.textMyInput.text())
messageBox = TTkMessageBox(
title="🤯 Error!!!",
text="An error has occurred!\nA lot of text 💥\nor Something",
icon=TTkMessageBox.Icon.Warning,
standardButtons=TTkMessageBox.StandardButton.Ok)
TTkHelper.overlay(self, messageBox, 2, 1, True)
# Close the window and exit the application
#TTk().quit()
root=TTk()
# Adding a log window to help debugging
logWin = TTkWindow(parent=root, text="Logs", pos=(30,10), size=(100,20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)
root.layout().addWidget(MyTextEditor(root))
root.mainloop() |
Hi Thanks for your answer and I have another problem. I want to make a widget (not a window) I want the user can not move the window and need only one frame with my form so I designed something in ttkDesigner but as the format of the window I made Python script like this: from TermTk import TTkUiLoader, TTk,TTkWidget
class MyTextEditor(TTkWidget):
def __init__(self, root):
self.root = root
TTkUiLoader.loadDict(
{'version': '2.0.0', 'tui': {'class': 'TTkContainer', 'params': {'Name': 'MainWidget', 'Position': [3, 2], 'Size': [94, 31], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [0, 0, 0, 0], 'Layout': 'TTkLayout'}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 94, 31)}, 'children': [{'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [1, 1], 'Size': [71, 22], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 69, 20)}, 'children': [{'class': 'TTkTextEdit', 'params': {'Name': 'TTkTextEdit-1', 'Position': [28, 6], 'Size': [20, 5], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Line Number': False, 'Line Number Starting': 0, 'Read Only': False, 'Multi Line': True}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLineEdit', 'params': {'Name': 'TTkLineEdit', 'Position': [10, 6], 'Size': [49, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'TTkButton', 'Position': [25, 10], 'Size': [20, 3], 'Min Width': 8, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Button', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},self)
root=TTk()
root.layout().addWidget(MyTextEditor(root))
root.mainloop() but I get this error:
Maybe need make an example for using only widget |
This is because you are using a TTkContainer instead of a widget: from TermTk import TTkUiLoader, TTk,TTkContainer
class MyTextEditor(TTkContainer):
def __init__(self, root):
self.root = root
TTkUiLoader.loadDict(
{'version': '2.0.0', 'tui': {'class': 'TTkContainer', 'params': {'Name': 'MainWidget', 'Position': [3, 2], 'Size': [94, 31], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [0, 0, 0, 0], 'Layout': 'TTkLayout'}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 94, 31)}, 'children': [{'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [1, 1], 'Size': [71, 22], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 69, 20)}, 'children': [{'class': 'TTkTextEdit', 'params': {'Name': 'TTkTextEdit-1', 'Position': [28, 6], 'Size': [20, 5], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Line Number': False, 'Line Number Starting': 0, 'Read Only': False, 'Multi Line': True}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkLineEdit', 'params': {'Name': 'TTkLineEdit', 'Position': [10, 6], 'Size': [49, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'TTkButton', 'Position': [25, 10], 'Size': [20, 3], 'Min Width': 8, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Button', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},self)
root=TTk()
root.layout().addWidget(MyTextEditor(root))
root.mainloop() |
I need a window that the user cannot move it. strict window with a fixed size. So what do you think you could suggest? |
In this code. how can I define an action for the button on the message box? if the user presses OK then something happens like quitting the program from TermTk import TTkUiLoader, TTk, TTkWindow, TTkLabel, TTkLog, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot
TTkLog.use_default_file_logging()
class MyTextEditor(TTkWindow):
def __init__(self, root):
self.root = root
TTkUiLoader.loadDict(
{'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},self)
self.textMyInput = self.getWidgetByName('licenseTxtInput')
self.checkButton = self.getWidgetByName('checkLicenseBtn')
self.checkButton.clicked.connect(self.onCheckButtonClick)
pyTTkSlot(str)
def onCheckButtonClick(self):
# You can use the log api to debug and print
# using the built in "print" would interfere with
# the drawing routine
TTkLog.debug(self.textMyInput.text())
messageBox = TTkMessageBox(
title="⛔️ Error!!!",
text="Ann error has occurred!\n{}".format(self.textMyInput.text()),
standardButtons=TTkMessageBox.StandardButton.Ok)
TTkHelper.overlay(self, messageBox, 2, 1, True)
# Close the window and exit the application
TTk().quit()
root=TTk()
# Adding a log window to help debugging
logWin = TTkWindow(parent=root, text="Logs", pos=(30,10), size=(100,20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)
root.layout().addWidget(MyTextEditor(root))
root.mainloop() |
I read this document for messagebox: (messagebox) messageBox = TTkMessageBox(
title="⛔️ Error!!!",
text="Ann error has occurred!\n{}".format(self.textMyInput.text()),
standardButtons=[TTkMessageBox.StandardButton.Ok,TTkMessageBox.StandardButton.Help])
TTkHelper.overlay(self, messageBox, 2, 1, True) |
Also, how can I colorize the title or text in the message box? For example for error message text should be red. I think you wrote docs for yourself it's very brief |
I wrote this code but I can't change the messagebox text or title to the red color: from TermTk import TTkUiLoader, TTk, TTkWindow, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot
TTkLog.use_default_file_logging()
class MyTextEditor(TTkWindow):
def __init__(self, root):
self.root = root
TTkUiLoader.loadDict(
{'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},self)
self.textMyInput = self.getWidgetByName('licenseTxtInput')
self.checkButton = self.getWidgetByName('checkLicenseBtn')
self.checkButton.clicked.connect(self.onCheckButtonClick)
pyTTkSlot(str)
def onCheckButtonClick(self):
# You can use the log api to debug and print
# using the built in "print" would interfere with
# the drawing routine
TTkLog.debug(self.textMyInput.text())
messageBox = TTkMessageBox(
title="⛔️ Error!!!",
text="Ann error has occurred!\n{}".format(self.textMyInput.text()),
standardButtons=TTkMessageBox.StandardButton.Ok | TTkMessageBox.StandardButton.Cancel | TTkMessageBox.StandardButton.Yes)
TTkHelper.overlay(self, messageBox, 2, 1, True)
messageBox.buttonSelected.connect(self._buttonSelected)
def _buttonSelected(self, btn):
buttonName = {
TTkMessageBox.StandardButton.Ok : 'Ok',
TTkMessageBox.StandardButton.Open : 'Open',
TTkMessageBox.StandardButton.Save : 'Save',
TTkMessageBox.StandardButton.Cancel : 'Cancel',
TTkMessageBox.StandardButton.Close : 'Close',
TTkMessageBox.StandardButton.Discard : 'Discard',
TTkMessageBox.StandardButton.Apply : 'Apply',
TTkMessageBox.StandardButton.Reset : 'Reset',
TTkMessageBox.StandardButton.RestoreDefaults : 'RestoreDefaults',
TTkMessageBox.StandardButton.Help : 'Help',
TTkMessageBox.StandardButton.SaveAll : 'SaveAll',
TTkMessageBox.StandardButton.Yes : 'Yes',
TTkMessageBox.StandardButton.YesToAll : 'YesToAll',
TTkMessageBox.StandardButton.No : 'No',
TTkMessageBox.StandardButton.NoToAll : 'NoToAll',
TTkMessageBox.StandardButton.Abort : 'Abort',
TTkMessageBox.StandardButton.Retry : 'Retry',
TTkMessageBox.StandardButton.Ignore : 'Ignore',
TTkMessageBox.StandardButton.NoButton : 'NoButton'}.get(int(btn),"???")
TTkLog.debug(f"btn: {int(btn)}")
TTkLog.debug(f"Selected: {buttonName}")
if buttonName == "Ok":
self.onMessageBoxButtonClick()
def onMessageBoxButtonClick(self):
# This function will be called when the user clicks the "Ok" button
TTk().quit()
root=TTk()
# Adding a log window to help debugging
logWin = TTkWindow(parent=root, text="Logs", pos=(30,10), size=(100,20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)
root.layout().addWidget(MyTextEditor(root))
root.mainloop() |
Is there any progress bar or something like that for example when the user clicks to check the checking button fills with dot's and repeats until connect to the license server and gets response something like this(but it doesn't work): from TermTk import TTkUiLoader, TTk, TTkWindow, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot
import time
TTkLog.use_default_file_logging()
class MyTextEditor(TTkWindow):
def __init__(self, root):
self.root = root
TTkUiLoader.loadDict(
{
"version": "2.0.0",
"tui": {
"class": "TTkWindow",
"params": {
"Name": "MainWindow",
"Position": [0, 0],
"Size": [83, 25],
"Min Width": 0,
"Min Height": 0,
"Max Width": 200,
"Max Height": 200,
"Visible": True,
"Enabled": True,
"ToolTip": "",
"Padding": [1, 1, 1, 1],
"Layout": "TTkLayout",
"Border": True,
"Title": "Check License",
"Window Flags": 0,
},
"layout": {
"class": "TTkLayout",
"params": {"Geometry": (0, 0, 81, 23)},
"children": [
{
"class": "TTkLabel",
"params": {
"Name": "TTkLabel",
"Position": [5, 11],
"Size": [21, 1],
"Min Width": 21,
"Min Height": 1,
"Max Width": 65536,
"Max Height": 65536,
"Visible": True,
"Enabled": True,
"ToolTip": "",
"Text": "Please Enter License:",
"Color": "\x1b[0m",
"Alignment": 0,
},
"row": 0,
"col": 0,
"rowspan": 1,
"colspan": 1,
},
{
"class": "TTkFrame",
"params": {
"Name": "TTkFrame",
"Position": [9, 12],
"Size": [62, 3],
"Min Width": 0,
"Min Height": 0,
"Max Width": 65536,
"Max Height": 65536,
"Visible": True,
"Enabled": True,
"ToolTip": "",
"Padding": [1, 1, 1, 1],
"Layout": "TTkLayout",
"Border": True,
"Title": "",
},
"layout": {
"class": "TTkLayout",
"params": {"Geometry": (0, 0, 60, 1)},
"children": [
{
"class": "TTkLineEdit",
"params": {
"Name": "licenseTxtInput",
"Position": [1, 0],
"Size": [58, 1],
"Min Width": 1,
"Min Height": 1,
"Max Width": 65536,
"Max Height": 1,
"Visible": True,
"Enabled": True,
"ToolTip": "",
"Input Type": 1,
"Text": "",
},
"row": 0,
"col": 0,
"rowspan": 1,
"colspan": 1,
}
],
},
"row": 0,
"col": 0,
"rowspan": 1,
"colspan": 1,
},
{
"class": "TTkButton",
"params": {
"Name": "checkLicenseBtn",
"Position": [30, 15],
"Size": [20, 3],
"Min Width": 7,
"Min Height": 3,
"Max Width": 65536,
"Max Height": 65536,
"Visible": True,
"Enabled": True,
"ToolTip": "",
"Text": "Check",
"Border": True,
"Checkable": False,
"Checked": False,
},
"row": 0,
"col": 0,
"rowspan": 1,
"colspan": 1,
},
],
},
},
"connections": [],
},self)
self.textMyInput = self.getWidgetByName('licenseTxtInput')
self.checkButton = self.getWidgetByName('checkLicenseBtn')
self.checkButton.clicked.connect(self.onCheckButtonClick)
pyTTkSlot(str)
def onCheckButtonClick(self):
TTkLog.debug(self.textMyInput.text())
self.checkButton.setDisabled()
self._checking()
self.textMyInput.setDisabled()
#self.checkButton.setDisabled()
# messageBox = TTkMessageBox(
# title="⛔️ Error!!!",
# text="Ann error has occurred!\n{}".format(self.textMyInput.text()),
# detailedText="OKKKK",
# standardButtons=TTkMessageBox.StandardButton.Ok | TTkMessageBox.StandardButton.Cancel | TTkMessageBox.StandardButton.Yes)
# TTkHelper.overlay(self, messageBox, 2, 1, True,True,True)
# messageBox.buttonSelected.connect(self.onMessageBoxButtonClick)
def _checking(self):
while True:
for i in range(4):
self.checkButton.setText("Checking" + "." * i)
time.sleep(1) # Wait for 1 second
def onMessageBoxButtonClick(self,btn):
if self._buttonName(btn) == "Ok":
TTk().quit()
def _buttonName(self,btn):
buttonName = {
TTkMessageBox.StandardButton.Ok : 'Ok',
TTkMessageBox.StandardButton.Open : 'Open',
TTkMessageBox.StandardButton.Save : 'Save',
TTkMessageBox.StandardButton.Cancel : 'Cancel',
TTkMessageBox.StandardButton.Close : 'Close',
TTkMessageBox.StandardButton.Discard : 'Discard',
TTkMessageBox.StandardButton.Apply : 'Apply',
TTkMessageBox.StandardButton.Reset : 'Reset',
TTkMessageBox.StandardButton.RestoreDefaults : 'RestoreDefaults',
TTkMessageBox.StandardButton.Help : 'Help',
TTkMessageBox.StandardButton.SaveAll : 'SaveAll',
TTkMessageBox.StandardButton.Yes : 'Yes',
TTkMessageBox.StandardButton.YesToAll : 'YesToAll',
TTkMessageBox.StandardButton.No : 'No',
TTkMessageBox.StandardButton.NoToAll : 'NoToAll',
TTkMessageBox.StandardButton.Abort : 'Abort',
TTkMessageBox.StandardButton.Retry : 'Retry',
TTkMessageBox.StandardButton.Ignore : 'Ignore',
TTkMessageBox.StandardButton.NoButton : 'NoButton'}.get(int(btn),"???")
return buttonName
root=TTk()
# Adding a log window to help debugging
logWin = TTkWindow(parent=root, text="Logs", pos=(30,10), size=(100,20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)
root.layout().addWidget(MyTextEditor(root))
root.mainloop() |
About the messagebox: I made an example here: Where a multicolor title is defined, more buttons are used and the actions are processed, tryItOnline from TermTk import TTkButton, TTk, TTkWindow, TTkString, TTkColor, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot
# To process the reeturn calue of rthe messagebox you need a slot that accept
# a Messagebox's Standard Button, the button pressed will be returned
@pyTTkSlot(TTkMessageBox.StandardButton)
def _processMessageBoxAction(btn):
if btn == TTkMessageBox.StandardButton.Discard:
TTkLog.debug("Discard Pressed 😎")
if btn == TTkMessageBox.StandardButton.Save:
TTkLog.debug("Save Pressed 😈")
if btn == TTkMessageBox.StandardButton.Cancel:
TTkLog.debug("Cancel Pressed 😇")
# In this example I am creating a message box that accept multiple actions
# and with colored text in the title and the main area
@pyTTkSlot()
def _testMessageBox():
TTkLog.debug("Initialize the MessageBox 😮")
messageBox = TTkMessageBox(
title = ( TTkString( f' Half Blue ', TTkColor.fg("#FFFF00")+TTkColor.bg("#0000FF")) +
TTkString( f' Half Green 🤯', TTkColor.fg("#000000")+TTkColor.bg("#00FF00")) ),
text= (
TTkString( f'Bold Line\n', TTkColor.BOLD) +
TTkString( f'Red Line\n', TTkColor.fg("#FF0000")) +
TTkString( f'Blue Line\n', TTkColor.fg("#FFFF00")+TTkColor.bg("#0000FF")) ),
icon=TTkMessageBox.Icon.Warning,
standardButtons=
TTkMessageBox.StandardButton.Discard |
TTkMessageBox.StandardButton.Save |
TTkMessageBox.StandardButton.Cancel )
messageBox.buttonSelected.connect(_processMessageBoxAction)
TTkHelper.overlay(None, messageBox, 5, 5, True)
root=TTk()
# Adding a log window to help debugging the messagebox pressed actions
logWin = TTkWindow(parent=root, text="Logs", pos=(5,10), size=(100,20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)
btn = TTkButton(parent=root, text="Test Messagebox",border=True)
btn.clicked.connect(_testMessageBox)
root.mainloop() |
There is an unofficial progeressbar widget and an animation helper that can be used to create this kind of animation, |
yes sure it can be animation of something that happened I tried to use the example you put link I got this error:
|
How can I switch between two containers? for example, I will show a form, and after the user clicks the check button the first container hides and the second container shows but when I set visible to False that object is removed from my page and it returns errors: self.getWidgetByName('InfoForm').setVisible(True) AttributeError: 'NoneType' object has no attribute 'setVisible' class msgType(Enum):
ERROR = 1
INFO = 2
MESSAGE = 3
WARNING = 4
class MyCheckLicense(TTkWindow):
def __init__(self, root):
self.root = root
TTkUiLoader.loadDict({
"version": "2.0.0",
"tui": {
"class": "TTkWindow",
"params": {
"Name": "MainLicense",
"Position": [0, 0],
"Size": [59, 22],
"Min Width": 0,
"Min Height": 0,
"Max Width": 65536,
"Max Height": 65536,
"Visible": True,
"Enabled": True,
"ToolTip": "",
"Padding": [0, 0, 0, 0],
"Layout": "TTkLayout",
"Border": True,
"Title": "Check License",
"Window Flags": 0,
},
"layout": {
"class": "TTkLayout",
"params": {"Geometry": (0, 0, 59, 22)},
"children": [
{
"class": "TTkContainer",
"params": {
"Name": "IpForm",
"Position": [1, 3],
"Size": [57, 18],
"Min Width": 0,
"Min Height": 0,
"Max Width": 65536,
"Max Height": 65536,
"Visible": True,
"Enabled": True,
"ToolTip": "",
"Padding": [0, 0, 0, 0],
"Layout": "TTkLayout",
},
"layout": {},
"row": 0,
"col": 0,
"rowspan": 1,
"colspan": 1,
},
{
"class": "TTkContainer",
"params": {
"Name": "InfoForm",
"Position": [1, 3],
"Size": [57, 18],
"Min Width": 0,
"Min Height": 0,
"Max Width": 65536,
"Max Height": 65536,
"Visible": True,
"Enabled": True,
"ToolTip": "",
"Padding": [0, 0, 0, 0],
"Layout": "TTkLayout",
},
"layout": {},
"row": 0,
"col": 0,
"rowspan": 1,
"colspan": 1,
}
],
},
},
"connections": [],
}
, self)
server_ip=get_ip_address().split(".")
self.getWidgetByName('InfoForm').setVisible(False)
self.getWidgetByName('IpPart1').setText(server_ip[0])
self.getWidgetByName('IpPart2').setText(server_ip[1])
self.getWidgetByName('IpPart3').setText(server_ip[2])
self.getWidgetByName('IpPart4').setText(server_ip[3])
self.checkButton = self.getWidgetByName('CheckBtn')
self.checkButton.clicked.connect(self.onCheckButtonClick)
pyTTkSlot(str)
def onCheckButtonClick(self):
self.checkButton.setDisabled()
self.checkButton.setText("Checking...")
self.getServerInfo()
def getServerInfo(self):
get_info=True
if get_info:
self.getWidgetByName('IpForm').setVisible(False)
self.getWidgetByName('InfoForm').setVisible(True)
def msgBox(self,type,text,title=None):
if title is None:
if type == msgType.ERROR:
title = ( TTkString( f'⛔️ Error!', TTkColor.fg("#FF0000")+TTkColor.BOLD) )
text = (TTkString( f'{text}', TTkColor.fg("#FF0000")) )
elif type == msgType.INFO:
title = ( TTkString( f'✅️ Successful!', TTkColor.bg("#FFFFFF")+TTkColor.fg("#008D19")+TTkColor.BOLD) )
text = (TTkString( f'{text}', TTkColor.fg("#5BFF6B")) )
elif type == msgType.WARNING:
title = ( TTkString( f'⚠️ Warning!', TTkColor.fg("#FF4800")+TTkColor.BOLD) )
text = (TTkString( f'{text}', TTkColor.fg("#FF4800")) )
else:
title = ( TTkString( f'ℹ️️ Info!', TTkColor.bg("#FFFFFF")+TTkColor.fg("#0062FF")+TTkColor.BOLD) )
text = (TTkString( f'{text}', TTkColor.fg("#FFFFFF")) )
messageBox = TTkMessageBox(
title=title,
text=text,
standardButtons=TTkMessageBox.StandardButton.Ok)
TTkHelper.overlay(self, messageBox, 22, 10, True)
def onMessageBoxButtonClick(self,btn):
if self._buttonName(btn) == "Ok":
TTk().quit()
def _buttonName(self,btn):
buttonName = {
TTkMessageBox.StandardButton.Ok : 'Ok',
TTkMessageBox.StandardButton.Open : 'Open',
TTkMessageBox.StandardButton.Save : 'Save',
TTkMessageBox.StandardButton.Cancel : 'Cancel',
TTkMessageBox.StandardButton.Close : 'Close',
TTkMessageBox.StandardButton.Discard : 'Discard',
TTkMessageBox.StandardButton.Apply : 'Apply',
TTkMessageBox.StandardButton.Reset : 'Reset',
TTkMessageBox.StandardButton.RestoreDefaults : 'RestoreDefaults',
TTkMessageBox.StandardButton.Help : 'Help',
TTkMessageBox.StandardButton.SaveAll : 'SaveAll',
TTkMessageBox.StandardButton.Yes : 'Yes',
TTkMessageBox.StandardButton.YesToAll : 'YesToAll',
TTkMessageBox.StandardButton.No : 'No',
TTkMessageBox.StandardButton.NoToAll : 'NoToAll',
TTkMessageBox.StandardButton.Abort : 'Abort',
TTkMessageBox.StandardButton.Retry : 'Retry',
TTkMessageBox.StandardButton.Ignore : 'Ignore',
TTkMessageBox.StandardButton.NoButton : 'NoButton'}.get(int(btn),"???")
return buttonName
root = TTk()
# Adding a log window to help debugging
logWin = TTkWindow(parent=root, text="Logs", pos=(30, 10), size=(100, 20), layout=TTkGridLayout())
TTkLogViewer(parent=logWin)
root.layout().addWidget(MyCheckLicense(root))
root.mainloop() |
Checking... and setting disable on the button doesn't show it shows the next form after waiting for sleep class MyCheckLicense(TTkWindow):
def __init__(self, root):
self.root = root
TTkUiLoader.loadDict({}, self)
server_ip=get_ip_address().split(".")
self.ip_form_geometry=self.getWidgetByName('IpForm').geometry()
self.info_form_geometry=self.getWidgetByName('InfoForm').geometry()
self.getWidgetByName('InfoForm').setGeometry(0,0,0,0)
self.getWidgetByName('IpPart1').setText(server_ip[0])
self.getWidgetByName('IpPart2').setText(server_ip[1])
self.getWidgetByName('IpPart3').setText(server_ip[2])
self.getWidgetByName('IpPart4').setText(server_ip[3])
self.checkButton = self.getWidgetByName('CheckBtn')
self.checkButton.clicked.connect(self.onCheckButtonClick)
pyTTkSlot(str)
def onCheckButtonClick(self):
self.checkButton.setDisabled()
self.checkButton.setText("Checking...")
self.getServerInfo()
def getServerInfo(self):
time.sleep(5)
get_info=True
if get_info:
self.getWidgetByName('IpForm').setGeometry(0,0,0,0)
self.getWidgetByName('InfoForm').setGeometry(*self.info_form_geometry) |
Sorry, I can't follow all those unrelated topics on this issue tracker. And, you can use this way to initialize a basic widget (without any ui loaded): class MyCheckLicense(TTkWindow):
def __init__(self, **kwargs):
super().__init__(**kwargs)
root = TTk()
MyCheckLicense(parent=root))
root.mainloop() otherwise: class MyCheckLicense(TTkWindow):
def __init__(self, **kwargs):
TTkUiLoader.loadDict(<THE_UI_DICT_DEFINITION>, self, kwargs)
root = TTk()
MyCheckLicense(parent=root))
root.mainloop() it is more handy if you want to treat your class like a standard widget |
|
It is just a note on the initialisation of the widget i.e. your first one could be initialised as: from TermTk import TTkUiLoader, TTk, TTkWindow, TTkLabel, TTkLog, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot
TTkLog.use_default_file_logging()
class MyTextEditor(TTkWindow):
def __init__(self, **kwargs):
TTkUiLoader.loadDict(
{'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},
self, kwargs)
root=TTk( title="Test LOGIN!!!" )
MyTextEditor(parent=root)
root.mainloop() |
You can use the classStyle, this is an alpha feature, I made an example here: from TermTk import TTkUiLoader, TTk, TTkWindow, TTkLabel, TTkLog, TTkMessageBox, TTkHelper, TTkGridLayout, TTkColor
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot
TTkLog.use_default_file_logging()
class MyTextEditor(TTkWindow):
classStyle = {
'default': {'color': TTkColor.RST,
'borderColor': TTkColor.fg('#FF0000')},
}
def __init__(self, **kwargs):
TTkUiLoader.loadDict(
{'version': '2.0.0', 'tui': {'class': 'TTkWindow', 'params': {'Name': 'MainWindow', 'Position': [0, 0], 'Size': [83, 25], 'Min Width': 0, 'Min Height': 0, 'Max Width': 200, 'Max Height': 200, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': 'Check License', 'Window Flags': 0}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 81, 23)}, 'children': [{'class': 'TTkLabel', 'params': {'Name': 'TTkLabel', 'Position': [5, 11], 'Size': [21, 1], 'Min Width': 21, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Please Enter License:', 'Color': '\x1b[0m', 'Alignment': 0}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkFrame', 'params': {'Name': 'TTkFrame', 'Position': [9, 12], 'Size': [62, 3], 'Min Width': 0, 'Min Height': 0, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Padding': [1, 1, 1, 1], 'Layout': 'TTkLayout', 'Border': True, 'Title': ''}, 'layout': {'class': 'TTkLayout', 'params': {'Geometry': (0, 0, 60, 1)}, 'children': [{'class': 'TTkLineEdit', 'params': {'Name': 'licenseTxtInput', 'Position': [1, 0], 'Size': [58, 1], 'Min Width': 1, 'Min Height': 1, 'Max Width': 65536, 'Max Height': 1, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Input Type': 1, 'Text': ''}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}, {'class': 'TTkButton', 'params': {'Name': 'checkLicenseBtn', 'Position': [30, 15], 'Size': [20, 3], 'Min Width': 7, 'Min Height': 3, 'Max Width': 65536, 'Max Height': 65536, 'Visible': True, 'Enabled': True, 'ToolTip': '', 'Text': 'Check', 'Border': True, 'Checkable': False, 'Checked': False}, 'row': 0, 'col': 0, 'rowspan': 1, 'colspan': 1}]}}, 'connections': []},
self, kwargs)
root=TTk( title="Test LOGIN!!!" )
MyTextEditor(parent=root)
root.mainloop() |
Thanks |
You can use the setStyle: from TermTk import TTkButton, TTk, TTkWindow, TTkString, TTkColor, TTkMessageBox, TTkHelper, TTkGridLayout
from TermTk import TTkLog, TTkLogViewer
from TermTk import pyTTkSlot
@pyTTkSlot()
def _testMessageBox():
messageBox = TTkMessageBox(
title = "Title",
text= "Content",
icon=TTkMessageBox.Icon.Warning)
messageBox.setStyle({
'default': {'color': TTkColor.RST,
'borderColor': TTkColor.fg('#FF0000')}})
TTkHelper.overlay(None, messageBox, 5, 5, True)
root=TTk()
btn = TTkButton(parent=root, text="Test Messagebox",border=True)
btn.clicked.connect(_testMessageBox)
root.mainloop() |
Hi I made a form with TTK Designer and it give me this code:
I used this example to make this code:
So i get this output:
How can I connect another window or another TTK Designer to my code? suppose I make a error window like this:
Output:
How can I join the output of TTK designer to my previous code for example if some condition happens then the new window opens
it was very helpful to make an example work with some form and processing user input
The text was updated successfully, but these errors were encountered: