create a tkinter windows with ok exit button in javascript

Unfortunately, tkinter is not available in JavaScript, it is a Python library for creating GUIs. However, there are a variety of libraries available for creating GUIs in JavaScript, such as Electron, React Native, or Vue Native. Here is an example using Electron:

index.tsx
const { app, BrowserWindow } = require('electron')

function createWindow () {
  // Create the browser window.
  let win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })

  // Load the index.html of the app.
  win.loadFile('index.html')

  // Add an OK/Exit button
  const {dialog} = require('electron')
  const options = {
      type: 'info',
      buttons: ['OK', 'Exit'],
      defaultId: 0,
      title: 'OK/Exit Button',
      message: 'Press OK to continue or Exit to close the window.',
      detail: 'This is a demo for an OK/Exit button.'
  }
  
  dialog.showMessageBox(null, options, (response) => {
      if (response === 0) {
          // OK button pressed
          console.log('OK')
      } else {
          // Exit button pressed
          console.log('EXIT')
          win.close()
      }
  })
}

app.on('ready', createWindow)
910 chars
40 lines

This code creates an Electron window with an OK/Exit button. When the button is pressed, a message box appears with the options "OK" and "Exit". If "OK" is pressed, the console will log "OK". If "Exit" is pressed, the console will log "EXIT" and the window will close.

gistlibby LogSnag