Skip to content

Commit d17776e

Browse files
fix error
fix Embedding Example error
1 parent 052bb71 commit d17776e

17 files changed

+74
-31
lines changed

Examples/Embedding/Embedding.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#coding=utf-8
2-
32
#import libs
3+
import sys
4+
import io
45
import Embedding_cmd
56
import Embedding_sty
67
import Fun
@@ -19,6 +20,7 @@ def __init__(self,root,isTKroot = True):
1920
uiName = self.__class__.__name__
2021
Fun.Register(uiName,'UIClass',self)
2122
self.root = root
23+
Fun.Register(uiName,'root',root)
2224
style = Embedding_sty.SetupStyle()
2325
if isTKroot == True:
2426
root.title("Form1")
@@ -28,16 +30,15 @@ def __init__(self,root,isTKroot = True):
2830
Form_1.place(x = 0,y = 0,width = 629,height = 510)
2931
Form_1.configure(bg = "#efefef")
3032
Form_1.configure(highlightthickness = 0)
31-
Fun.Register(uiName,'root',root)
3233
Fun.Register(uiName,'Form_1',Form_1)
3334
#Create the elements of root
34-
Frame_2= tkinter.Frame(root)
35+
Frame_2 = tkinter.Frame(root)
3536
Fun.Register(uiName,'Frame_2',Frame_2)
3637
Frame_2.place(x = 9,y = 12,width = 609,height = 160)
3738
Frame_2.configure(bg = "#ffffff")
3839
Frame_2.configure(relief = "flat")
3940
Page1.Page1(Frame_2,False)
40-
NoteBook_3= tkinter.ttk.Notebook(root)
41+
NoteBook_3 = tkinter.ttk.Notebook(root)
4142
Fun.Register(uiName,'NoteBook_3',NoteBook_3)
4243
NoteBook_3.place(x = 10,y = 188,width = 606,height = 312)
4344
PageFrame_1 = tkinter.ttk.Frame(NoteBook_3)

Examples/Embedding/Embedding_cmd.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818

1919

2020

21+
22+

Examples/Embedding/Fun.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ def GetText(uiName,elementName):
157157
elementName = G_UIElementAlias[uiName][elementName]
158158
if uiName in G_UIElementVariableArray:
159159
if elementName in G_UIElementVariableArray[uiName]:
160-
return G_UIElementVariableArray[uiName][elementName].get()
160+
text = G_UIElementVariableArray[uiName][elementName].get()
161+
return text
161162
if uiName in G_UIElementArray:
162163
if elementName in G_UIElementArray[uiName]:
163164
if elementName.find('Text_') >= 0:
@@ -288,7 +289,7 @@ def CenterDlg(uiName,popupDlg,dw=0,dh=0):
288289
if dh == 0:
289290
dh = popupDlg.winfo_height()
290291
root = GetElement(uiName,'root')
291-
if root != None:
292+
if root != None and popupDlg != root:
292293
sw = root.winfo_width()
293294
sh = root.winfo_height()
294295
sx = root.winfo_x()

Examples/Embedding/Page1.py

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,76 @@
22

33
#import libs
44
import Page1_cmd
5-
import Page1_sty
65
import Fun
7-
import os
86
import tkinter
97
from tkinter import *
108
import tkinter.ttk
119
import tkinter.font
10+
ElementBGArray={}
11+
ElementBGArray_Resize={}
12+
ElementBGArray_IM={}
13+
1214
#Add your Varial Here: (Keep This Line of comments)
1315
#Define UI Class
1416
class Page1:
1517
def __init__(self,root,isTKroot = True):
1618
uiName = self.__class__.__name__
1719
Fun.Register(uiName,'UIClass',self)
1820
self.root = root
19-
style = Page1_sty.SetupStyle()
21+
Fun.Register(uiName,'root',root)
2022
if isTKroot == True:
2123
root.title("Form1")
22-
Fun.CenterDlg(uiName,root,627,163)
23-
root['background'] = '#efefef'
24+
root.geometry("574x150")
2425
Form_1= tkinter.Canvas(root,width = 10,height = 4)
25-
Form_1.place(x = 0,y = 0,width = 627,height = 163)
26+
Form_1.place(x = 0,y = 0,width = 574,height = 150)
2627
Form_1.configure(bg = "#efefef")
27-
Form_1.configure(highlightthickness = 0)
28-
Fun.Register(uiName,'root',root)
2928
Fun.Register(uiName,'Form_1',Form_1)
3029
Group_1_Variable = Fun.AddTKVariable(uiName,'Group_1')
3130
Group_1_Variable.set(1)
3231
#Create the elements of root
32+
Label_2= tkinter.Label(root,text="姓名",width = 10,height = 4)
33+
Label_2.place(x = 18,y = 13,width = 82,height = 20)
34+
Fun.Register(uiName,'Label_2',Label_2)
35+
Entry_3_Variable = Fun.AddTKVariable(uiName,'Entry_3')
36+
Entry_3= tkinter.Entry(root,textvariable=Entry_3_Variable)
37+
Entry_3.place(x = 120,y = 14,width = 120,height = 20)
38+
Entry_3.configure(relief = "sunken")
39+
Fun.Register(uiName,'Entry_3',Entry_3)
40+
Label_4= tkinter.Label(root,text="性别",width = 10,height = 4)
41+
Label_4.place(x = 18,y = 44,width = 82,height = 20)
42+
Fun.Register(uiName,'Label_4',Label_4)
43+
RadioButton_5= tkinter.Radiobutton(root,variable=Group_1_Variable,value=1,text="男",anchor=tkinter.W)
44+
RadioButton_5.place(x = 116,y = 45,width = 68,height = 19)
45+
Fun.Register(uiName,'RadioButton_5',RadioButton_5,None,'Group_1')
46+
RadioButton_6= tkinter.Radiobutton(root,variable=Group_1_Variable,value=2,text="女",anchor=tkinter.W)
47+
RadioButton_6.place(x = 191,y = 44,width = 100,height = 20)
48+
Fun.Register(uiName,'RadioButton_6',RadioButton_6,None,'Group_1')
49+
Label_7= tkinter.Label(root,text="年龄",width = 10,height = 4)
50+
Label_7.place(x = 18,y = 78,width = 82,height = 20)
51+
Fun.Register(uiName,'Label_7',Label_7)
52+
Entry_8_Variable = Fun.AddTKVariable(uiName,'Entry_8')
53+
Entry_8= tkinter.Entry(root,textvariable=Entry_8_Variable)
54+
Entry_8.place(x = 121,y = 75,width = 120,height = 20)
55+
Entry_8.configure(relief = "sunken")
56+
Fun.Register(uiName,'Entry_8',Entry_8)
57+
Label_9= tkinter.Label(root,text="地址",width = 10,height = 4)
58+
Label_9.place(x = 18,y = 110,width = 82,height = 20)
59+
Fun.Register(uiName,'Label_9',Label_9)
60+
ComboBox_10_Variable = Fun.AddTKVariable(uiName,'ComboBox_10')
61+
ComboBox_10= tkinter.ttk.Combobox(root,textvariable=ComboBox_10_Variable, state="readonly")
62+
ComboBox_10.place(x = 120,y = 110,width = 124,height = 20)
63+
ComboBox_10.configure(state = "readonly")
64+
ComboBox_10["values"]=['北京','天津','上海']
65+
ComboBox_10.current(0)
66+
Fun.Register(uiName,'ComboBox_10',ComboBox_10)
67+
Button_11= tkinter.Button(root,text="增加",width = 10,height = 4)
68+
Button_11.place(x = 448,y = 103,width = 100,height = 28)
69+
Button_11.configure(command=lambda:Page1_cmd.Button_11_onCommand(uiName,"Button_11"))
70+
Fun.Register(uiName,'Button_11',Button_11)
3371
#Inital all element's Data
3472
Fun.InitElementData(uiName)
3573
#Add Some Logic Code Here: (Keep This Line of comments)
3674

37-
3875
#Create the root of Kinter
3976
if __name__ == '__main__':
4077
root = tkinter.Tk()

Examples/Embedding/Page1_cmd.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@
77
import tkinter.filedialog
88
from tkinter import *
99
import Fun
10-
ElementBGArray={}
11-
ElementBGArray_Resize={}
12-
ElementBGArray_IM={}
13-
10+
def Button_11_onCommand(uiName,widgetName):
11+
name = Fun.GetText(uiName,'Entry_3')
12+
gender = Fun.GetTKVariable(uiName,'Group_1')
13+
if gender == 1:
14+
gender ='男'
15+
else:
16+
gender ='女'
17+
age = Fun.GetText(uiName,'Entry_8')
18+
combobox = Fun.GetElement(uiName,'ComboBox_10')
19+
address=combobox.get()
20+
treeview = Fun.GetElement('TabPage1','TreeView_2')
21+
treeview.insert('','end',values=(name,gender,age,address))
22+
Fun.SetText(uiName,'Entry_3','')
23+
Fun.SetTKVariable(uiName,'Group_1',1)
24+
Fun.SetText(uiName,'Entry_8',0)
25+
combobox.current(0)

Examples/Embedding/TabPage1.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,15 @@
1414
class TabPage1:
1515
def __init__(self,root,isTKroot = True):
1616
uiName = self.__class__.__name__
17-
Fun.G_UIElementArray[uiName]={}
18-
Fun.G_UIElementUserDataArray[uiName]={}
19-
global ElementBGArray
20-
global ElementBGArray_Resize
21-
global ElementBGArray_IM
2217
Fun.Register(uiName,'UIClass',self)
2318
self.root = root
19+
Fun.Register(uiName,'root',root)
2420
if isTKroot == True:
2521
root.title("Form1")
2622
root.geometry("611x320")
2723
Form_1= tkinter.Canvas(root,width = 10,height = 4)
2824
Form_1.place(x = 0,y = 0,width = 611,height = 320)
2925
Form_1.configure(bg = "#efefef")
30-
Fun.Register(uiName,'root',root)
3126
Fun.Register(uiName,'Form_1',Form_1)
3227
#Create the elements of root
3328
TreeView_2= tkinter.ttk.Treeview(root,show="tree")

Examples/Embedding/TabPage2.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,15 @@
1414
class TabPage2:
1515
def __init__(self,root,isTKroot = True):
1616
uiName = self.__class__.__name__
17-
Fun.G_UIElementArray[uiName]={}
18-
Fun.G_UIElementUserDataArray[uiName]={}
19-
global ElementBGArray
20-
global ElementBGArray_Resize
21-
global ElementBGArray_IM
2217
Fun.Register(uiName,'UIClass',self)
2318
self.root = root
19+
Fun.Register(uiName,'root',root)
2420
if isTKroot == True:
2521
root.title("Form1")
2622
root.geometry("565x295")
2723
Form_1= tkinter.Canvas(root,width = 10,height = 4)
2824
Form_1.place(x = 0,y = 0,width = 565,height = 295)
2925
Form_1.configure(bg = "#efefef")
30-
Fun.Register(uiName,'root',root)
3126
Fun.Register(uiName,'Form_1',Form_1)
3227
#Create the elements of root
3328
Canvas_2= tkinter.Canvas(root)
431 Bytes
Binary file not shown.
317 Bytes
Binary file not shown.
24.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)