2021年5月28日 星期五

開發Windows/Linux皆可用的AEDT GUI

用WPF開發視窗雖然方便,可惜只能支援Windows。用Windows Forms控件則可以做出Windows/Linux皆可用的GUI,可以透過Viual Studio C#視窗編程先拖拉出GUI外觀,再將其生成之程式碼做一個修改即可使用在IronPyrhon。

simpleGUI.py

import clr
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')

from System import Drawing
from System.Windows.Forms import *

class MyForm(Form):
def __init__(self):
self.textBox1 = TextBox()
self.button1 = Button()
self.label1 = Label()
self.SuspendLayout()


self.textBox1.Location = Drawing.Point(12, 46)
self.textBox1.Name = "textBox1"
self.textBox1.Size = Drawing.Size(309, 30)
self.textBox1.TabIndex = 0

self.button1.BackColor = Drawing.SystemColors.HotTrack
self.button1.Font = Drawing.Font("Microsoft Sans Serif", 12)
self.button1.ForeColor = Drawing.Color.GhostWhite
self.button1.Location = Drawing.Point(216, 116)
self.button1.Name = "button1"
self.button1.Size = Drawing.Size(99, 53)
self.button1.TabIndex = 1
self.button1.Text = "Print"
self.button1.UseVisualStyleBackColor = False
self.button1.Click += self.button1_Click_1

self.label1.AutoSize = True
self.label1.Font = Drawing.Font("Microsoft Sans Serif", 12)
self.label1.Location = Drawing.Point(12, 9)
self.label1.Name = "label1"
self.label1.Size = Drawing.Size(55, 25)
self.label1.TabIndex = 2
self.label1.Text = "Input"

self.AutoScaleDimensions = Drawing.SizeF(8, 16)

self.AutoSize = True
self.ClientSize = Drawing.Size(333, 178)
self.Controls.Add(self.label1)
self.Controls.Add(self.button1)
self.Controls.Add(self.textBox1)
self.FormBorderStyle = FormBorderStyle.FixedSingle
self.MaximizeBox = False
self.MinimizeBox = False
self.Name = "Form1"
self.Text = "Simpe Linux Window"
self.TopMost = True
self.ResumeLayout(False)
self.PerformLayout()

def button1_Click_1(self, sender, e):
AddWarningMessage(self.textBox1.Text)

form = MyForm()
Application.Run(form)


(圖一) Linux執行

(圖二) Windows執行




沒有留言:

張貼留言