class Lnput_lnitialization(): def __init__(self, top, Number_of_rows): self.top = top int(data_demo.window_width // 3.9875) int(data_demo.window_height // 1.138) self.frame = tk.Frame(self.top, bg='Black', highlightthickness=2, highlightbackground='Black') self.frame.place(relx=0.739, rely=0.083, width=int(data_demo.window_width // 3.87), height=int(data_demo.window_height // 1.15)) self.canvas = tk.Canvas(self.frame) self.canvas.place(relx=0, rely=0, width=int(data_demo.window_width // 3.9875), height=int(data_demo.window_height // 1.15)) scrollbar = tk.Scrollbar(self.frame, command=self.canvas.yview) scrollbar.pack(side="right", fill="y") self.canvas.configure(yscrollcommand=scrollbar.set) self.button_frame = tk.Frame(self.canvas, bg='Yellow') self.canvas.create_window((0, 0), window=self.button_frame, anchor="nw") self.Content(Number_of_rows) # 在步骤栏创建填写框 def Content(self, Number_of_rows): x = 0.01 y = 0.01 for a in range(Number_of_rows): var = tk.IntVar() checkbutton1 = Checkbutton(self.button_frame, variable=var, text="{}".format(data_demo.Serial_Number), compound='right') checkbutton1.grid(row=data_demo.Serial_Number, column=1, padx=3, pady=5) data_demo.checkbutton1_boxs.append(checkbutton1) data_demo.checkbutton_bool.append(var) combobox1 = ttk.Combobox(self.button_frame, values=["遥控", "语音", "随机"], width=4) combobox1.grid(row=data_demo.Serial_Number, column=2, padx=6, pady=5) data_demo.comboxox_boxs.append(combobox1)怎么让他自适应大小
时间: 2024-03-18 15:42:41 浏览: 57
可以考虑使用`pack_propagate(False)`方法来禁止自动调整大小,然后使用`pack(fill=BOTH, expand=True)`来使其自适应大小。具体修改方法如下:
1. 将`self.button_frame`的`pack()`方法更改为`pack_propagate(False)`,以禁止自动调整大小。
2. 在`self.canvas.create_window()`方法中添加`pack(fill=BOTH, expand=True)`,以使其自适应大小。
修改后的代码如下:
```
self.button_frame = tk.Frame(self.canvas, bg='Yellow')
self.button_frame.pack_propagate(False) # 禁止自动调整大小
self.canvas.create_window((0, 0), window=self.button_frame, anchor="nw")
self.button_frame.pack(fill=BOTH, expand=True) # 使其自适应大小
```
相关问题
class Lnput_lnitialization(): def __init__(self, top, Number_of_rows): self.top = top int(data_demo.window_width // 3.9875) int(data_demo.window_height // 1.138) self.frame = tk.Frame(self.top, bg='Black', highlightthickness=2, highlightbackground='Black') self.frame.place(relx=0.739, rely=0.083, width=int(data_demo.window_width // 3.87), height=int(data_demo.window_height // 1.15)) self.canvas = tk.Canvas(self.frame) self.canvas.place(relx=0, rely=0, width=int(data_demo.window_width // 3.9875), height=int(data_demo.window_height // 1.15)) scrollbar = tk.Scrollbar(self.frame, command=self.canvas.yview) scrollbar.pack(side="right", fill="y") self.canvas.configure(yscrollcommand=scrollbar.set) self.button_frame = tk.Frame(self.canvas, bg='Yellow') # self.button_frame.place(relwidth=0.98, relheight=1) self.canvas.create_window((0, 0), window=self.button_frame, anchor="nw") self.Content(Number_of_rows) # 在步骤栏创建填写框 def Content(self, Number_of_rows): x = 0.01 y = 0.01 for a in range(Number_of_rows): var = tk.IntVar() checkbutton1 = Checkbutton(self.button_frame, variable=var, text="{}".format(data_demo.Serial_Number), compound='right') checkbutton1.grid(row=data_demo.Serial_Number, column=1, padx=3, pady=5) # checkbutton1.place(relx=x, rely=y) data_demo.checkbutton1_boxs.append(checkbutton1) data_demo.checkbutton_bool.append(var)为什么只能用grid不能用plice
在这段代码中,使用grid()方法和place()方法都是可以的,它们都是用来在Tkinter窗口中摆放控件的方法。grid()方法是用来将控件放置在网格中的,而place()方法则是用来将控件放置在指定的位置上的。不过,在这段代码中,使用了Canvas控件来作为容器,并使用create_window()方法将Frame控件添加到Canvas中,这时候使用grid()方法和place()方法都会出现问题。
因为Canvas控件是不支持grid()和place()方法的,所以在使用Canvas控件时,应该使用create_window()方法将其他控件添加到Canvas中。所以,在这段代码中,使用了create_window()方法来将Frame控件添加到Canvas中,并使用了grid()方法来将Checkbutton控件添加到Frame中,这样就可以实现对Checkbutton控件的摆放了。
写一段c语言代码,首先务必注意所有函数的声明必须在main之前,否则会出现错误,另外不要使用stl。最后,代码的规范性,包括变量命名、排版、注释等也纳入考量范围。以下是这段代码的要求:Description: 假设两个按元素值非递减有序排列的线性表A和B,均以单链表作为存储结构,试编写程序,将A表和B表归并成一个按元素值非递增有序排列的线性表C,并要求利用原表(即A表和B表的)结点空间存放表C。 lnput: 第一行输入两个正整数m,n(m,n<=100),用空格分开,分别表示线性表A和B中元素个数,其后两行分别输入单链表A和B. Output: 输出单链表C。 Sample lnput: 5 5 1 3 7 12 16 2 6 7 13 20 Sample Output: 20 16 13 12 7 7 6 3 2 1
#include<stdio.h>
#include<stdlib.h>
//定义链表节点结构体
typedef struct Node{
int data;
struct Node* next;
}Node;
//函数声明
Node* merge(Node* headA, Node* headB);
void printList(Node* head);
int main(){
//输入线性表A和B的元素个数
int m, n;
scanf("%d%d", &m, &n);
//创建链表A和B
Node* headA = NULL;
Node* headB = NULL;
Node* pA = NULL;
Node* pB = NULL;
for(int i=0; i<m; i++){
int data;
scanf("%d", &data);
Node* node = (Node*)malloc(sizeof(Node));
node->data = data;
node->next = NULL;
if(headA == NULL){
headA = node;
pA = node;
}
else{
pA->next = node;
pA = node;
}
}
for(int i=0; i<n; i++){
int data;
scanf("%d", &data);
Node* node = (Node*)malloc(sizeof(Node));
node->data = data;
node->next = NULL;
if(headB == NULL){
headB = node;
pB = node;
}
else{
pB->next = node;
pB = node;
}
}
//合并链表A和B
Node* headC = merge(headA, headB);
//输出链表C
printList(headC);
return 0;
}
//合并链表函数
Node* merge(Node* headA, Node* headB){
if(headA == NULL){
return headB;
}
if(headB == NULL){
return headA;
}
//定义链表C的头节点
Node* headC = NULL;
if(headA->data >= headB->data){
headC = headA;
headA = headA->next;
}
else{
headC = headB;
headB = headB->next;
}
//指向链表C的当前节点
Node* pC = headC;
while(headA && headB){
if(headA->data >= headB->data){
pC->next = headA;
headA = headA->next;
}
else{
pC->next = headB;
headB = headB->next;
}
pC = pC->next;
}
if(headA){
pC->next = headA;
}
else{
pC->next = headB;
}
//反转链表C
Node* pre = NULL;
Node* cur = headC;
Node* next = NULL;
while(cur){
next = cur->next;
cur->next = pre;
pre = cur;
cur = next;
}
headC = pre;
return headC;
}
//输出链表函数
void printList(Node* head){
while(head){
printf("%d ", head->data);
head = head->next;
}
}
阅读全文